use systemd to control docker-compose setup

This commit is contained in:
Robert Kaussow 2019-05-10 10:55:14 +02:00
parent 0d264f39a1
commit 0b919dccc7
7 changed files with 44 additions and 10 deletions

View File

@ -7,8 +7,9 @@ droneci_secret: myveryownsecret
# Path to the license key file # Path to the license key file
# droneci_license_key: # defaults to not set # droneci_license_key: # defaults to not set
droneci_restart_policy: always
droneci_server_image: "drone/drone:{{ droneci_version }}" droneci_server_image: "drone/drone:{{ droneci_version }}"
droneci_server_restart_policy: always
droneci_server_exposed_port: 8080 droneci_server_exposed_port: 8080
droneci_server_exposed_ip: 127.0.0.1 droneci_server_exposed_ip: 127.0.0.1
# droneci_server_memory_limit: 512m # defaults to not set # droneci_server_memory_limit: 512m # defaults to not set
@ -16,7 +17,6 @@ droneci_server_exposed_ip: 127.0.0.1
# droneci_server_extra_hosts: [] # droneci_server_extra_hosts: []
droneci_agent_image: "drone/agent:{{ droneci_version }}" droneci_agent_image: "drone/agent:{{ droneci_version }}"
droneci_agent_restart_policy: always
dronevi_agent_capacity: 2 dronevi_agent_capacity: 2
# droneci_agent_memory_limit: 512m # defaults to not set # droneci_agent_memory_limit: 512m # defaults to not set
# droneci_agent_memory_reservation: 256m # defaults to not set # droneci_agent_memory_reservation: 256m # defaults to not set

View File

@ -1,9 +1,9 @@
--- ---
- name: Restart container - name: Restart container
docker_service: systemd:
project_src: "{{ droneci_service_directory }}" state: restarted
build: no daemon_reload: yes
restarted: true name: drone
listen: __drone_restart listen: __drone_restart
become: True become: True
become_user: root become_user: root

View File

@ -2,3 +2,4 @@
- import_tasks: prepare.yml - import_tasks: prepare.yml
- import_tasks: setup.yml - import_tasks: setup.yml
- import_tasks: nginx.yml - import_tasks: nginx.yml
- import_tasks: post.yml

10
tasks/post.yml Normal file
View File

@ -0,0 +1,10 @@
---
- block:
- name: Ensure drone service is up and running
systemd:
state: started
daemon_reload: yes
enabled: yes
name: drone
become: True
become_user: root

View File

@ -13,15 +13,18 @@
mode: 0644 mode: 0644
notify: __drone_restart notify: __drone_restart
- name: Create systemd unit files
template:
src: "etc/systemd/system/drone.service.j2"
dest: "/etc/systemd/system/drone.service"
mode: 0644
notify: __drone_restart
- name: Copy license key file is defined - name: Copy license key file is defined
copy: copy:
src: "{{ droneci_license_key }}" src: "{{ droneci_license_key }}"
dest: "{{ droneci_service_directory }}/{{ droneci_license_key | basename }}" dest: "{{ droneci_service_directory }}/{{ droneci_license_key | basename }}"
mode: 0600 mode: 0600
when: droneci_license_key is defined when: droneci_license_key is defined
- name: Ensure drone ci containers are up and running
docker_service:
project_src: "{{ droneci_service_directory }}"
become: True become: True
become_user: root become_user: root

View File

@ -0,0 +1,19 @@
#jinja2:lstrip_blocks: True
# {{ ansible_managed }}
[Unit]
Description=Drone CI compose service
Requires=docker.service
After=docker.service
[Service]
Restart={{ droneci_restart_policy }}
WorkingDirectory={{ droneci_service_directory }}
ExecStartPre=/bin/docker-compose down
ExecStartPre=/bin/docker-compose rm -f
ExecStart=/usr/bin/docker-compose up
ExecStop=/usr/bin/docker-compose down
[Install]
WantedBy=multi-user.target

View File

@ -25,6 +25,7 @@ services:
environment: environment:
- DRONE_SERVER_HOST={{ droneci_host | urlsplit('hostname') }} - DRONE_SERVER_HOST={{ droneci_host | urlsplit('hostname') }}
- DRONE_SERVER_PROTO={{ droneci_host | urlsplit('scheme') }} - DRONE_SERVER_PROTO={{ droneci_host | urlsplit('scheme') }}
- DRONE_AGENTS_ENABLED=true
- DRONE_RPC_SECRET={{ droneci_secret }} - DRONE_RPC_SECRET={{ droneci_secret }}
- DRONE_USER_CREATE={{ droneci_admins | default(omit) | join(",") }} - DRONE_USER_CREATE={{ droneci_admins | default(omit) | join(",") }}
- DRONE_LOGS_COLOR=true - DRONE_LOGS_COLOR=true