59 lines
2 KiB
YAML
59 lines
2 KiB
YAML
---
|
|
- name: Read Postgres password
|
|
set_fact:
|
|
app_core_postgres_password: "{{ POSTGRES_PASSWORD | default(lookup('env', 'POSTGRES_PASSWORD')) }}"
|
|
|
|
- name: Read S3 configuration (optional)
|
|
set_fact:
|
|
app_core_s3_bucket: "{{ S3_BUCKET | default(lookup('env', 'S3_BUCKET')) | default('') }}"
|
|
app_core_s3_region: "{{ S3_REGION | default(lookup('env', 'S3_REGION')) | default('us-east-1') }}"
|
|
app_core_s3_endpoint: "{{ S3_ENDPOINT | default(lookup('env', 'S3_ENDPOINT')) | default('') }}"
|
|
app_core_s3_access_key_id: "{{ S3_ACCESS_KEY_ID | default(lookup('env', 'S3_ACCESS_KEY_ID')) | default('') }}"
|
|
app_core_s3_secret_access_key: "{{ S3_SECRET_ACCESS_KEY | default(lookup('env', 'S3_SECRET_ACCESS_KEY')) | default('') }}"
|
|
no_log: true
|
|
|
|
- name: Fail if Postgres password is missing
|
|
fail:
|
|
msg: "POSTGRES_PASSWORD is required"
|
|
when: app_core_postgres_password | length == 0
|
|
|
|
- name: Create app directory
|
|
file:
|
|
path: /opt/app
|
|
state: directory
|
|
|
|
- name: Write app environment file (optional)
|
|
copy:
|
|
dest: /opt/app/app.env
|
|
mode: '0600'
|
|
content: |
|
|
S3_BUCKET={{ app_core_s3_bucket }}
|
|
S3_REGION={{ app_core_s3_region }}
|
|
S3_ENDPOINT={{ app_core_s3_endpoint | default('https://' ~ app_core_s3_region ~ '.linodeobjects.com') }}
|
|
S3_ACCESS_KEY_ID={{ app_core_s3_access_key_id }}
|
|
S3_SECRET_ACCESS_KEY={{ app_core_s3_secret_access_key }}
|
|
when:
|
|
- (app_core_s3_bucket | length) > 0
|
|
- (app_core_s3_access_key_id | length) > 0
|
|
- (app_core_s3_secret_access_key | length) > 0
|
|
no_log: true
|
|
|
|
- name: Copy Docker Compose file for app
|
|
template:
|
|
src: docker-compose.yml.j2
|
|
dest: /opt/app/docker-compose.yml
|
|
|
|
- name: Ensure app network exists
|
|
command: docker network inspect app
|
|
register: app_network
|
|
changed_when: false
|
|
failed_when: false
|
|
|
|
- name: Create app network if missing
|
|
command: docker network create app
|
|
when: app_network.rc != 0
|
|
|
|
- name: Deploy app stack
|
|
command: docker compose up -d
|
|
args:
|
|
chdir: /opt/app
|