fix: inject image ref into accounts deploy

This commit is contained in:
Haitao Pan 2026-04-12 14:23:10 +08:00
parent 335ee6ef81
commit 4c62883bfc
5 changed files with 22 additions and 1 deletions

View File

@ -3,6 +3,16 @@
gather_facts: false
become: true
vars:
accounts_service_image_ref: >-
{{
(lookup('ansible.builtin.env', 'ACCOUNTS_IMAGE_REF') | default('', true) | trim)
or
(
(lookup('ansible.builtin.env', 'ACCOUNTS_IMAGE_REPO') | default('ghcr.io/x-evor/accounts', true))
~ ':'
~ (lookup('ansible.builtin.env', 'ACCOUNTS_IMAGE_TAG') | default('latest', true))
)
}}
accounts_service_image_repo: >-
{{ lookup('ansible.builtin.env', 'ACCOUNTS_IMAGE_REPO')
| default('ghcr.io/x-evor/accounts', true) }}

View File

@ -1,4 +1,5 @@
---
accounts_service_image_ref: "{{ accounts_service_image_repo }}:{{ accounts_service_image_tag }}"
accounts_service_image_repo: ghcr.io/x-evor/accounts
accounts_service_image_tag: latest
accounts_service_pull_image: true

View File

@ -60,6 +60,14 @@
state: present
insertbefore: BOF
- name: Ensure managed IMAGE is present for {{ accounts_service_target.name }}
ansible.builtin.lineinfile:
path: "{{ accounts_service_target.env_file }}"
regexp: '^IMAGE='
line: 'IMAGE={{ accounts_service_image_ref }}'
state: present
insertafter: '^CONFIG_TEMPLATE='
- name: Render managed account config for {{ accounts_service_target.name }}
ansible.builtin.template:
src: account.yaml.j2

View File

@ -1,6 +1,7 @@
# Managed by Ansible. Do not edit on the host.
CONFIG_PATH=/etc/xcontrol/account.yaml
CONFIG_TEMPLATE=/etc/xcontrol/account.template.yaml
IMAGE={{ accounts_service_image_ref }}
DB_HOST={{ accounts_service_env_defaults.DB_HOST }}
DB_NAME={{ accounts_service_env_defaults.DB_NAME }}
DB_PASSWORD={{ accounts_service_env_defaults.DB_PASSWORD }}

View File

@ -1,11 +1,12 @@
services:
app:
image: "{{ accounts_service_image_repo }}:{{ accounts_service_image_tag }}"
image: "{{ accounts_service_image_ref }}"
container_name: {{ accounts_service_target.container_name }}
restart: unless-stopped
env_file:
- ./env/app.env
environment:
IMAGE: "{{ accounts_service_image_ref }}"
PORT: "{{ accounts_service_container_port }}"
volumes:
- ./config/account.yaml:/etc/xcontrol/account.template.yaml:ro