From a75b2895b0e918ed4d531b238ee7e14959098136 Mon Sep 17 00:00:00 2001 From: Maxime Soudant <maximesoudant@MacBook-Pro-de-Maxime.local> Date: Wed, 20 Sep 2023 16:47:52 +0200 Subject: [PATCH] suit deployment --- .gitlab-ci.yml | 7 ++++- ansible/application/docker-compose.yml | 9 +++++++ {gitlab => ansible/gitlab}/docker-compose.yml | 1 + ansible/playbook.yml | 26 +++++++++++-------- 4 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 ansible/application/docker-compose.yml rename {gitlab => ansible/gitlab}/docker-compose.yml (85%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ac7e9b5..c02c3f0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,7 @@ +stages: + - "build" + - "deploy" + docker-build: # Use the official docker image. image: docker:latest @@ -27,6 +31,7 @@ docker-build: deploy_prod: stage: deploy + image: ansible/ansible:latest script: - echo "Deploy to production server" environment: @@ -34,4 +39,4 @@ deploy_prod: url: http://172.28.100.149:443 rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - when: manual \ No newline at end of file + when: on_success \ No newline at end of file diff --git a/ansible/application/docker-compose.yml b/ansible/application/docker-compose.yml new file mode 100644 index 0000000..08c6fb4 --- /dev/null +++ b/ansible/application/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3' +services: + application: + image: 'maximesoudant/application_web_devops_m2:latest' + container_name: 'application' + ports: + - "443:443" + restart: unless-stopped + diff --git a/gitlab/docker-compose.yml b/ansible/gitlab/docker-compose.yml similarity index 85% rename from gitlab/docker-compose.yml rename to ansible/gitlab/docker-compose.yml index 583fcd1..28196b8 100644 --- a/gitlab/docker-compose.yml +++ b/ansible/gitlab/docker-compose.yml @@ -2,6 +2,7 @@ version: '3' services: gitlab-runner: image: 'gitlab/gitlab-runner:latest' + container_name: 'gitlab_runner' volumes: - /var/run/docker.sock:/var/run/docker.sock - ./config:/etc/gitlab-runner diff --git a/ansible/playbook.yml b/ansible/playbook.yml index 09ecc1b..24d10b3 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -71,16 +71,20 @@ become: true tasks: - - name: Container node-web-app - community.docker.docker_container: - name: node-web-app - image: maximesoudant/application_web_devops_m2 - state: started - restart_policy: always - ports: - - "443:443" - pull: true - container_default_behavior: compatibility + - name: Create application directory if it does not exist + ansible.builtin.file: + path: ./application + state: directory + + - name: Copy docker-compose.yml file + copy: + src: ./application/docker-compose.yml + dest: ./application/docker-compose.yml + + - name: Launch docker_compose + community.docker.docker_compose: + project_src: ./application/ + state: present - name: gitlab runner hosts: Git_vm @@ -95,7 +99,7 @@ - name: Copy docker-compose.yml file copy: - src: ../gitlab/docker-compose.yml + src: ./gitlab/docker-compose.yml dest: ./gitlab/docker-compose.yml - name: Launch docker_compose -- GitLab