forked from jakub/ansible
feat: enhance Glance deployment with improved configuration and error handling
This commit is contained in:
@@ -1,22 +1,25 @@
|
|||||||
# docker-compose-glance.yml
|
# docker-compose-glance.yml
|
||||||
|
|
||||||
|
name: glance
|
||||||
|
|
||||||
services:
|
services:
|
||||||
glance:
|
glance:
|
||||||
container_name: glance
|
container_name: glance
|
||||||
image: glanceapp/glance:latest
|
image: glanceapp/glance:latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
# Relative to project_src (~/.ansible-compose), so no username is hardcoded.
|
# Relative to project_src (~/.ansible-compose/glance), so no username is
|
||||||
# The playbook creates this directory and uploads glance.yml into it.
|
# hardcoded. The playbook creates this directory and uploads glance.yml.
|
||||||
# The image entrypoint is /app/glance --config /app/config/glance.yml,
|
# The image entrypoint is /app/glance --config /app/config/glance.yml,
|
||||||
# so the file must be named exactly glance.yml.
|
# so the file must be named exactly glance.yml.
|
||||||
- ./glance/config:/app/config
|
- ./config:/app/config
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
environment:
|
environment:
|
||||||
# Used by the calendar widget and by relative timestamps
|
# Used by the calendar widget and by relative timestamps
|
||||||
- TZ=Europe/Prague
|
- TZ=Europe/Prague
|
||||||
# Optional: raises the GitHub API limit for the releases widget.
|
env_file:
|
||||||
# Referenced from glance.yml as ${GITHUB_TOKEN}; inject it as a
|
# Deployed by the playbook from the persistent env file on the VM.
|
||||||
# Semaphore secret instead of committing it here.
|
# Provides GITHUB_TOKEN, referenced from glance.yml as ${GITHUB_TOKEN}.
|
||||||
# - GITHUB_TOKEN=${GITHUB_TOKEN}
|
- .env
|
||||||
ports:
|
ports:
|
||||||
- '9445:8080'
|
- '9445:8080'
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
# glance.yml - source of truth lives in git, deployed by update_glance.yml
|
# glance.yml - source of truth lives in git, deployed by update_glance.yml
|
||||||
|
# GITHUB_TOKEN comes from the persistent env file on the VM, never from git.
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
- name: Home
|
- name: Home
|
||||||
@@ -77,9 +78,9 @@ pages:
|
|||||||
|
|
||||||
- type: releases
|
- type: releases
|
||||||
cache: 1d
|
cache: 1d
|
||||||
# Without authentication the GitHub API allows up to 60 requests per hour.
|
# Without a token the GitHub API allows up to 60 requests per hour.
|
||||||
# Uncomment and pass GITHUB_TOKEN in as an environment variable to raise it.
|
# A read-only token with no scopes raises this to 5000.
|
||||||
# token: ${GITHUB_TOKEN}
|
token: ${GITHUB_TOKEN}
|
||||||
repositories:
|
repositories:
|
||||||
- trezor/trezor-firmware
|
- trezor/trezor-firmware
|
||||||
- glanceapp/glance
|
- glanceapp/glance
|
||||||
|
|||||||
+62
-11
@@ -11,22 +11,50 @@
|
|||||||
|
|
||||||
# Glance settings
|
# Glance settings
|
||||||
glance_project: glance
|
glance_project: glance
|
||||||
|
glance_port: 9445
|
||||||
glance_compose_filename: "docker-compose-glance.yml"
|
glance_compose_filename: "docker-compose-glance.yml"
|
||||||
glance_service: glance
|
glance_service: glance
|
||||||
glance_port: 9445
|
|
||||||
|
|
||||||
# Config delivery (git -> controller -> target).
|
# Own project directory, so .env does not collide with other stacks
|
||||||
# Must match the ./glance/config volume in the compose file.
|
glance_remote_dir: "{{ compose_remote_base }}/glance"
|
||||||
glance_config_local: "{{ playbook_dir }}/files/glance/glance.yml"
|
|
||||||
glance_config_remote_dir: "{{ compose_remote_base }}/glance/config"
|
glance_config_remote_dir: "{{ compose_remote_base }}/glance/config"
|
||||||
|
|
||||||
|
# Config delivery (git -> controller -> target)
|
||||||
|
glance_config_local: "{{ playbook_dir }}/files/glance/glance.yml"
|
||||||
|
|
||||||
|
# Persistent env file on the VM (NOT in git)
|
||||||
|
glance_env_persistent: "{{ compose_remote_base }}/env/glance.env"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Ensure remote compose directory exists
|
- name: Ensure remote base directory exists
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ compose_remote_base }}"
|
path: "{{ compose_remote_base }}"
|
||||||
state: directory
|
state: directory
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
|
|
||||||
|
- name: Ensure remote env directory exists
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ compose_remote_base }}/env"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Check for persistent Glance env file
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ glance_env_persistent }}"
|
||||||
|
register: glance_env_stat
|
||||||
|
|
||||||
|
- name: Abort when Glance env is missing
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: >-
|
||||||
|
Missing persistent env file: {{ glance_env_persistent }}.
|
||||||
|
Create it on the VM with a GITHUB_TOKEN variable.
|
||||||
|
when: not glance_env_stat.stat.exists
|
||||||
|
|
||||||
|
- name: Ensure Glance project directory exists
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ glance_remote_dir }}"
|
||||||
|
state: directory
|
||||||
|
mode: "0755"
|
||||||
|
|
||||||
- name: Ensure Glance config directory exists
|
- name: Ensure Glance config directory exists
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ glance_config_remote_dir }}"
|
path: "{{ glance_config_remote_dir }}"
|
||||||
@@ -36,7 +64,7 @@
|
|||||||
- name: Upload Glance compose file to remote host
|
- name: Upload Glance compose file to remote host
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: "{{ compose_local_dir }}/{{ glance_compose_filename }}"
|
src: "{{ compose_local_dir }}/{{ glance_compose_filename }}"
|
||||||
dest: "{{ compose_remote_base }}/{{ glance_compose_filename }}"
|
dest: "{{ glance_remote_dir }}/{{ glance_compose_filename }}"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
|
||||||
- name: Upload Glance configuration
|
- name: Upload Glance configuration
|
||||||
@@ -45,10 +73,17 @@
|
|||||||
dest: "{{ glance_config_remote_dir }}/glance.yml"
|
dest: "{{ glance_config_remote_dir }}/glance.yml"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
|
||||||
|
- name: Deploy Glance .env into compose directory
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: "{{ glance_env_persistent }}"
|
||||||
|
dest: "{{ glance_remote_dir }}/.env"
|
||||||
|
remote_src: true
|
||||||
|
mode: "0600"
|
||||||
|
|
||||||
- name: Pull latest Glance image
|
- name: Pull latest Glance image
|
||||||
community.docker.docker_compose_v2:
|
community.docker.docker_compose_v2:
|
||||||
project_name: "{{ glance_project }}"
|
project_name: "{{ glance_project }}"
|
||||||
project_src: "{{ compose_remote_base }}"
|
project_src: "{{ glance_remote_dir }}"
|
||||||
files:
|
files:
|
||||||
- "{{ glance_compose_filename }}"
|
- "{{ glance_compose_filename }}"
|
||||||
pull: always
|
pull: always
|
||||||
@@ -56,7 +91,7 @@
|
|||||||
- name: Recreate Glance service
|
- name: Recreate Glance service
|
||||||
community.docker.docker_compose_v2:
|
community.docker.docker_compose_v2:
|
||||||
project_name: "{{ glance_project }}"
|
project_name: "{{ glance_project }}"
|
||||||
project_src: "{{ compose_remote_base }}"
|
project_src: "{{ glance_remote_dir }}"
|
||||||
files:
|
files:
|
||||||
- "{{ glance_compose_filename }}"
|
- "{{ glance_compose_filename }}"
|
||||||
services:
|
services:
|
||||||
@@ -64,13 +99,15 @@
|
|||||||
state: present
|
state: present
|
||||||
recreate: always
|
recreate: always
|
||||||
|
|
||||||
|
- name: Verify Glance is serving
|
||||||
|
block:
|
||||||
- name: Wait for Glance port
|
- name: Wait for Glance port
|
||||||
ansible.builtin.wait_for:
|
ansible.builtin.wait_for:
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
port: "{{ glance_port }}"
|
port: "{{ glance_port }}"
|
||||||
timeout: 60
|
timeout: 60
|
||||||
|
|
||||||
- name: Check Glance HTTP endpoint
|
- name: Check Glance HTTP endpoint (retry until ready)
|
||||||
ansible.builtin.uri:
|
ansible.builtin.uri:
|
||||||
url: "http://127.0.0.1:{{ glance_port }}/"
|
url: "http://127.0.0.1:{{ glance_port }}/"
|
||||||
status_code: 200
|
status_code: 200
|
||||||
@@ -80,9 +117,23 @@
|
|||||||
until: glance_http.status == 200
|
until: glance_http.status == 200
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Show Glance container logs on failed startup
|
rescue:
|
||||||
|
- name: Collect Glance container logs
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: "docker logs --tail 50 glance"
|
cmd: "docker logs --tail 50 glance"
|
||||||
register: glance_logs
|
register: glance_logs
|
||||||
changed_when: false
|
changed_when: false
|
||||||
when: glance_http is failed
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Show Glance container logs
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ glance_logs.stderr_lines | default([]) + glance_logs.stdout_lines | default([]) }}"
|
||||||
|
|
||||||
|
- name: Fail after showing logs
|
||||||
|
ansible.builtin.fail:
|
||||||
|
msg: "Glance did not become healthy on port {{ glance_port }}. See container logs above."
|
||||||
|
|
||||||
|
- name: Clean up legacy compose file from shared base directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ compose_remote_base }}/{{ glance_compose_filename }}"
|
||||||
|
state: absent
|
||||||
Reference in New Issue
Block a user