Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favor docker compose v2 in ansible tasks #1835

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ansible/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ roles:

collections:
- community.general
- community.docker
- devsec.hardening
2 changes: 1 addition & 1 deletion ansible/roles/backup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

- name: Query id of database container
command:
cmd: docker-compose -f docker-compose.yml -f docker-compose.prod.yml ps -q db
cmd: docker compose -f docker-compose.yml -f docker-compose.prod.yml ps -q db
chdir: /home/ansible
register: get_container_id
tags:
Expand Down
17 changes: 8 additions & 9 deletions ansible/roles/installation/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- ../docker-compose.prod.yml
- ../docker-compose.traefik.yml

- name: Run `docker-compose up`
- name: Run `docker compose up`
environment:
DOCKER_IMAGE_TAG: "{{ docker_image_tag }}"
RAILS_ENV: "{{ rails.environment }}"
Expand Down Expand Up @@ -56,23 +56,22 @@
THREE_SIXTY_DIALOG_PARTNER_ID: "{{ rails.three_sixty_dialog.partner.id | default('') }}"
THREE_SIXTY_DIALOG_PARTNER_USERNAME: "{{ rails.three_sixty_dialog.partner.username | default('') }}"
THREE_SIXTY_DIALOG_PARTNER_PASSWORD: "{{ rails.three_sixty_dialog.partner.password | default('') }}"

community.general.docker_compose:
community.docker.docker_compose_v2:
project_src: /home/ansible
build: no
debug: yes
pull: yes
restarted: yes
recreate: always
build: never
pull: always
wait: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwr18 this is a nice new feature that will ensure that all containers are healthy before proceeding. In our pair-programming today we were facing the issue of silent failures.

files:
- docker-compose.yml
- docker-compose.prod.yml
- docker-compose.traefik.yml

- name: Prune outdated images
community.general.docker_prune:
community.docker.docker_prune:
images: yes

- name: Create and migrate database
command:
cmd: docker-compose -f docker-compose.yml -f docker-compose.prod.yml exec app bin/rails db:migrate
cmd: docker compose -f docker-compose.yml -f docker-compose.prod.yml exec app bin/rails db:migrate
chdir: /home/ansible
16 changes: 5 additions & 11 deletions ansible/roles/local_restore/tasks/restore_backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
src: "{{ backup_host_folder.path }}/tmp/100eyes-storage.tgz"
dest: "{{ playbook_dir }}/.."

- name: Install docker-compose python package
ansible.builtin.pip:
name: docker-compose

- name: Run `docker-compose up`
community.general.docker_compose:
- name: Run `docker compose up`
community.docker.docker_compose_v2:
project_src: "{{ playbook_dir }}/.."
debug: yes
state: present
services:
- db
Expand All @@ -42,17 +37,16 @@

- name: Re-create empty databse and restore database backup
command:
cmd: "docker-compose exec -T db bash -c \"{{ item }}\""
cmd: "docker compose exec -T db bash -c \"{{ item }}\""
chdir: "{{ playbook_dir }}/.."
loop:
- dropdb app_development -U postgres --if-exists
- createdb app_development -U postgres
- pg_restore -d app_development -U postgres --no-owner --role=postgres < /tmp/100eyes-db-dump

- name: Run `docker-compose down`
community.general.docker_compose:
- name: Run `docker compose down`
community.docker.docker_compose_v2:
project_src: "{{ playbook_dir }}/.."
debug: yes
state: absent
files:
- docker-compose.yml
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/signal/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@
ansible.builtin.cron:
name: "Receive signal messages"
minute: "*" # job gets run every minute
job: "/usr/local/bin/docker-compose -f /home/ansible/docker-compose.yml -f /home/ansible/docker-compose.prod.yml exec -T app bin/rails signal:receive_messages"
job: "/usr/bin/docker compose -f /home/ansible/docker-compose.yml -f /home/ansible/docker-compose.prod.yml exec -T app bin/rails signal:receive_messages"
9 changes: 3 additions & 6 deletions ansible/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
- role: gantsign.inotify
inotify_max_user_watches: 524288
- role: geerlingguy.pip
vars:
pip_install_packages:
- name: "docker < 7.0.0"
- name: docker-compose
- name: passlib
pip_install_packages:
- name: passlib
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passlib is required for htpasswd role. The other two seem not required.

- role: geerlingguy.docker
docker_packages_state: latest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm willing to keep this variable. Opinions/thoughts?

vars:
docker_compose_version: "1.27.4"
docker_users:
- ansible
- role: installation
Expand Down
Loading