mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-22 04:31:13 +01:00
Compare commits
2 Commits
d138458b94
...
d1b2d8e653
Author | SHA1 | Date | |
---|---|---|---|
d1b2d8e653 | |||
e889f7cf24 |
@ -2,21 +2,40 @@
|
|||||||
- name: "include tasks nginx-docker-proxy-domain.yml"
|
- name: "include tasks nginx-docker-proxy-domain.yml"
|
||||||
include_tasks: nginx-docker-proxy-domain.yml
|
include_tasks: nginx-docker-proxy-domain.yml
|
||||||
|
|
||||||
- name: "create {{ repository_directory }}"
|
- name: register repository_directory_register
|
||||||
file:
|
stat:
|
||||||
path: "{{ repository_directory }}"
|
path: "{{repository_directory}}"
|
||||||
state: directory
|
register: repository_directory_register
|
||||||
mode: 0755
|
|
||||||
|
- name: checkout repository
|
||||||
|
ansible.builtin.shell: git checkout .
|
||||||
|
become: true
|
||||||
|
args:
|
||||||
|
chdir: "{{repository_directory}}"
|
||||||
|
when: repository_directory_register.stat.exists
|
||||||
|
|
||||||
|
- name: "backup docker-compose.yml if it exists"
|
||||||
|
command: >
|
||||||
|
mv "{{ docker_compose_file_path }}" "{{ docker_compose_backup_path }}"
|
||||||
|
args:
|
||||||
|
removes: "{{ docker_compose_file_path }}"
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: pull docker repository
|
- name: pull docker repository
|
||||||
git:
|
git:
|
||||||
repo: "https://github.com/opf/openproject-deploy"
|
repo: "https://github.com/opf/openproject-deploy"
|
||||||
dest: "{{repository_directory}}"
|
dest: "{{ repository_directory }}"
|
||||||
update: yes
|
update: yes
|
||||||
notify: recreate openproject
|
notify: recreate openproject
|
||||||
become: true
|
become: true
|
||||||
register: git_result
|
register: git_result
|
||||||
ignore_errors: true
|
|
||||||
|
- name: "restore docker-compose.yml from backup"
|
||||||
|
command: >
|
||||||
|
mv "{{ docker_compose_backup_path }}" "{{ docker_compose_file_path }}"
|
||||||
|
args:
|
||||||
|
removes: "{{ docker_compose_backup_path }}"
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: Warn if repo is not reachable
|
- name: Warn if repo is not reachable
|
||||||
debug:
|
debug:
|
||||||
@ -26,5 +45,11 @@
|
|||||||
- name: "copy .env"
|
- name: "copy .env"
|
||||||
template:
|
template:
|
||||||
src: env.j2
|
src: env.j2
|
||||||
dest: "{{docker_compose_instance_directory}}.env"
|
dest: "{{ docker_compose_instance_directory }}.env"
|
||||||
|
notify: recreate openproject
|
||||||
|
|
||||||
|
- name: "copy docker-compose.yml"
|
||||||
|
template:
|
||||||
|
src: docker-compose.yml.j2
|
||||||
|
dest: "{{ docker_compose_file_path }}"
|
||||||
notify: recreate openproject
|
notify: recreate openproject
|
117
roles/docker-openproject/templates/docker-compose.yml.j2
Normal file
117
roles/docker-openproject/templates/docker-compose.yml.j2
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
version: "3.7"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
frontend:
|
||||||
|
backend:
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pgdata:
|
||||||
|
opdata:
|
||||||
|
|
||||||
|
x-op-restart-policy: &restart_policy
|
||||||
|
restart: unless-stopped
|
||||||
|
x-op-image: &image
|
||||||
|
image: openproject/community:${TAG:-13}
|
||||||
|
x-op-app: &app
|
||||||
|
<<: [*image, *restart_policy]
|
||||||
|
environment:
|
||||||
|
OPENPROJECT_HTTPS: "${OPENPROJECT_HTTPS:-true}"
|
||||||
|
OPENPROJECT_HOST__NAME: "${OPENPROJECT_HOST__NAME:-localhost:8080}"
|
||||||
|
OPENPROJECT_HSTS: "${OPENPROJECT_HSTS:-true}"
|
||||||
|
RAILS_CACHE_STORE: "memcache"
|
||||||
|
OPENPROJECT_CACHE__MEMCACHE__SERVER: "cache:11211"
|
||||||
|
OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}"
|
||||||
|
DATABASE_URL: "${DATABASE_URL:-postgres://postgres:p4ssw0rd@db/openproject?pool=20&encoding=unicode&reconnect=true}"
|
||||||
|
RAILS_MIN_THREADS: ${RAILS_MIN_THREADS:-4}
|
||||||
|
RAILS_MAX_THREADS: ${RAILS_MAX_THREADS:-16}
|
||||||
|
# set to true to enable the email receiving feature. See ./docker/cron for more options
|
||||||
|
IMAP_ENABLED: "${IMAP_ENABLED:-false}"
|
||||||
|
volumes:
|
||||||
|
- "${OPDATA:-opdata}:/var/openproject/assets"
|
||||||
|
|
||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: postgres:13
|
||||||
|
<<: *restart_policy
|
||||||
|
stop_grace_period: "3s"
|
||||||
|
volumes:
|
||||||
|
- "${PGDATA:-pgdata}:/var/lib/postgresql/data"
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-p4ssw0rd}
|
||||||
|
POSTGRES_DB: openproject
|
||||||
|
networks:
|
||||||
|
- backend
|
||||||
|
|
||||||
|
cache:
|
||||||
|
image: memcached
|
||||||
|
<<: *restart_policy
|
||||||
|
networks:
|
||||||
|
- backend
|
||||||
|
|
||||||
|
proxy:
|
||||||
|
<<: [*image, *restart_policy]
|
||||||
|
command: "./docker/prod/proxy"
|
||||||
|
ports:
|
||||||
|
- "${PORT:-8080}:80"
|
||||||
|
environment:
|
||||||
|
APP_HOST: web
|
||||||
|
OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}"
|
||||||
|
depends_on:
|
||||||
|
- web
|
||||||
|
networks:
|
||||||
|
- frontend
|
||||||
|
|
||||||
|
web:
|
||||||
|
<<: *app
|
||||||
|
command: "./docker/prod/web"
|
||||||
|
networks:
|
||||||
|
- frontend
|
||||||
|
- backend
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
- cache
|
||||||
|
- seeder
|
||||||
|
labels:
|
||||||
|
- autoheal=true
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:8080${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}/health_checks/default"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 3
|
||||||
|
start_period: 30s
|
||||||
|
|
||||||
|
autoheal:
|
||||||
|
image: willfarrell/autoheal:1.2.0
|
||||||
|
volumes:
|
||||||
|
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||||
|
environment:
|
||||||
|
AUTOHEAL_CONTAINER_LABEL: autoheal
|
||||||
|
AUTOHEAL_START_PERIOD: 600
|
||||||
|
AUTOHEAL_INTERVAL: 30
|
||||||
|
|
||||||
|
worker:
|
||||||
|
<<: *app
|
||||||
|
command: "./docker/prod/worker"
|
||||||
|
networks:
|
||||||
|
- backend
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
- cache
|
||||||
|
- seeder
|
||||||
|
|
||||||
|
cron:
|
||||||
|
<<: *app
|
||||||
|
command: "./docker/prod/cron"
|
||||||
|
networks:
|
||||||
|
- backend
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
- cache
|
||||||
|
- seeder
|
||||||
|
|
||||||
|
seeder:
|
||||||
|
<<: *app
|
||||||
|
command: "./docker/prod/seeder"
|
||||||
|
restart: on-failure
|
||||||
|
networks:
|
||||||
|
- backend
|
@ -18,5 +18,5 @@ RAILS_MIN_THREADS=4
|
|||||||
RAILS_MAX_THREADS=16
|
RAILS_MAX_THREADS=16
|
||||||
|
|
||||||
# The following volumes are default
|
# The following volumes are default
|
||||||
# PGDATA="pgdata"
|
PGDATA="pgdata"
|
||||||
# OPDATA="opdata"
|
OPDATA="opdata"
|
@ -1,2 +1,4 @@
|
|||||||
repository_directory: "{{ path_docker_compose_instances }}openproject/"
|
repository_directory: "{{ path_docker_compose_instances }}openproject/"
|
||||||
docker_compose_instance_directory: "{{repository_directory}}compose/"
|
docker_compose_instance_directory: "{{repository_directory}}compose/"
|
||||||
|
docker_compose_file_path: "{{docker_compose_instance_directory}}docker-compose.yml"
|
||||||
|
docker_compose_backup_path: "/tmp/openproject-docker-compose-backup.yml"
|
@ -4,6 +4,9 @@
|
|||||||
#
|
#
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
|
errors = 0
|
||||||
|
|
||||||
def bash(command):
|
def bash(command):
|
||||||
print(command)
|
print(command)
|
||||||
@ -26,6 +29,13 @@ def print_bash(command):
|
|||||||
print(list_to_string(output))
|
print(list_to_string(output))
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def find_docker_compose_file(directory):
|
||||||
|
for root, _, files in os.walk(directory):
|
||||||
|
for file in files:
|
||||||
|
if file == 'docker-compose.yml':
|
||||||
|
return os.path.join(root, file)
|
||||||
|
return None
|
||||||
|
|
||||||
waiting_time=600
|
waiting_time=600
|
||||||
blocker_running=True
|
blocker_running=True
|
||||||
while blocker_running:
|
while blocker_running:
|
||||||
@ -48,8 +58,16 @@ for failed_container in failed_containers:
|
|||||||
unfiltered_failed_docker_compose_repositories.append(failed_container.split('-')[0])
|
unfiltered_failed_docker_compose_repositories.append(failed_container.split('-')[0])
|
||||||
|
|
||||||
filtered_failed_docker_compose_repositories=list(dict.fromkeys(unfiltered_failed_docker_compose_repositories))
|
filtered_failed_docker_compose_repositories=list(dict.fromkeys(unfiltered_failed_docker_compose_repositories))
|
||||||
|
|
||||||
for filtered_failed_docker_compose_repository in filtered_failed_docker_compose_repositories:
|
for filtered_failed_docker_compose_repository in filtered_failed_docker_compose_repositories:
|
||||||
print("restarting unhealthy container: " + filtered_failed_docker_compose_repository)
|
compose_file_path = find_docker_compose_file('/home/administrator/docker-compose/' + filtered_failed_docker_compose_repository)
|
||||||
print_bash('cd /home/administrator/docker-compose/' + filtered_failed_docker_compose_repository + '/ && docker-compose restart')
|
|
||||||
|
if compose_file_path:
|
||||||
|
print("Restarting unhealthy container in:", compose_file_path)
|
||||||
|
print_bash(f'cd {os.path.dirname(compose_file_path)} && docker-compose restart')
|
||||||
|
else:
|
||||||
|
print("Error: Docker Compose file not found for:", filtered_failed_docker_compose_repository)
|
||||||
|
errors += 1
|
||||||
|
|
||||||
print("finished restart procedure.")
|
print("finished restart procedure.")
|
||||||
|
exit(errors)
|
Loading…
Reference in New Issue
Block a user