From af8b241df507469f20032d7af6f5d77b03031144 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 14 Jun 2019 23:30:07 +0800 Subject: [PATCH] feat(env): add server and agent config --- tasks/drone-agent.yml | 14 ++++++++++---- tasks/drone-server.yml | 23 +++++++++++------------ templates/drone-agent.env.j2 | 10 ++++++++++ templates/drone-server.env.j2 | 25 +++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 templates/drone-agent.env.j2 create mode 100644 templates/drone-server.env.j2 diff --git a/tasks/drone-agent.yml b/tasks/drone-agent.yml index 2086b25..fc141ec 100644 --- a/tasks/drone-agent.yml +++ b/tasks/drone-agent.yml @@ -1,4 +1,12 @@ --- +- name: copy config for drone agent + template: + src: "drone-agent.env.j2" + dest: "/etc/drone/drone-agent.env" + register: drone_agent_config + tags: + - configuration + - name: run drone agent docker_container: name: "drone-agent" @@ -7,9 +15,7 @@ restart_policy: always volumes: - /var/run/docker.sock:/var/run/docker.sock - env: - DRONE_RPC_SERVER={{ drone_rpc_server }} - DRONE_RPC_SECRET={{ drone_rpc_secret }} - DRONE_RUNNER_CAPACITY={{ drone_runner_capacity }} + env_file: /etc/drone/drone-agent.env + when: drone_agent_config is defined and drone_agent_config.changed tags: - drone-agent diff --git a/tasks/drone-server.yml b/tasks/drone-server.yml index 79b55cc..d560c77 100644 --- a/tasks/drone-server.yml +++ b/tasks/drone-server.yml @@ -1,5 +1,13 @@ --- -- name: Creates directory +- name: copy config for drone server + template: + src: "drone-server.env.j2" + dest: "/etc/drone/drone-server.env" + register: drone_server_config + tags: + - configuration + +- name: Creates sqlite directory file: path: "{{ item }}" state: directory @@ -19,16 +27,7 @@ - "{{ drone_host_port }}:80" volumes: - "{{ drone_dir }}:/data" - env: - DRONE_SERVER_HOST: "{{ drone_server_host }}" - DRONE_SERVER_PROTO: "{{ drone_server_proto }}" - DRONE_TLS_AUTOCERT: "false" - DRONE_RPC_SECRET: "{{ drone_rpc_secret }}" - DRONE_AGENTS_ENABLED: "true" - DRONE_GITHUB_SERVER: "https://github.com" - DRONE_GITHUB_CLIENT_ID: "{{ drone_github_client_id }}" - DRONE_GITHUB_CLIENT_SECRET: "{{ drone_github_client_secret }}" - DRONE_LOGS_PRETTY: "{{ drone_logs_pretty }}" - DRONE_LOGS_COLOR: "{{ drone_logs_color }}" + env_file: /etc/drone/drone-server.env + when: drone_server_config is defined and drone_server_config.changed tags: - drone-server diff --git a/templates/drone-agent.env.j2 b/templates/drone-agent.env.j2 new file mode 100644 index 0000000..7418784 --- /dev/null +++ b/templates/drone-agent.env.j2 @@ -0,0 +1,10 @@ +{% if drone_rpc_server is defined %} +DRONE_RPC_SERVER={{ drone_rpc_server }} +{% endif %} +{% if drone_rpc_secret is defined %} +DRONE_RPC_SECRET={{ drone_rpc_secret }} +{% endif %} +{% if drone_runner_capacity is defined %} +DRONE_RUNNER_CAPACITY={{ drone_runner_capacity }} +{% endif %} +DRONE_LOGS_DEBUG=true diff --git a/templates/drone-server.env.j2 b/templates/drone-server.env.j2 new file mode 100644 index 0000000..b9933df --- /dev/null +++ b/templates/drone-server.env.j2 @@ -0,0 +1,25 @@ +{% if drone_server_host is defined %} +DRONE_SERVER_HOST={{ drone_server_host }} +{% endif %} +{% if drone_server_proto is defined %} +DRONE_SERVER_PROTO={{ drone_server_proto }} +{% endif %} +DRONE_TLS_AUTOCERT=false +{% if drone_rpc_secret is defined %} +DRONE_RPC_SECRET={{ drone_rpc_secret }} +{% endif %} +DRONE_AGENTS_ENABLED=true +DRONE_GITHUB_SERVER=https://github.com +{% if drone_github_client_id is defined %} +DRONE_GITHUB_CLIENT_ID={{ drone_github_client_id }} +{% endif %} +{% if drone_github_client_secret is defined %} +DRONE_GITHUB_CLIENT_SECRET={{ drone_github_client_secret }} +{% endif %} +{% if drone_logs_pretty is defined %} +DRONE_LOGS_PRETTY={{ drone_logs_pretty }} +{% endif %} +{% if drone_logs_color is defined %} +DRONE_LOGS_COLOR={{ drone_logs_color }} +{% endif %} +DRONE_LOGS_DEBUG=true