diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ac7e9b51165b62446b2de584666e8dc7fa0b4298..c02c3f02a2286e23f62ca34652d78a308cc01a1c 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 0000000000000000000000000000000000000000..08c6fb4707048ef38b5b6fd8bcfa4def54d35c19
--- /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 583fcd158c65fd0c8875555c6d491fefc04919d3..28196b803c6169a3b76710cc640d7613ba7aac5b 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 09ecc1b9d8bddabdccfd0e845c051fb0bfa04f5c..24d10b3b8d44b5295f245a87d976d4b97786d247 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