From 4c62883bfc8abc05b4b4ea8bf6be200b9cccdfd5 Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Sun, 12 Apr 2026 14:23:10 +0800 Subject: [PATCH] fix: inject image ref into accounts deploy --- deploy_accounts_svc_plus.yml | 10 ++++++++++ roles/vhosts/accounts_service/defaults/main.yml | 1 + roles/vhosts/accounts_service/tasks/target.yml | 8 ++++++++ roles/vhosts/accounts_service/templates/app.env.j2 | 1 + .../accounts_service/templates/docker-compose.yml.j2 | 3 ++- 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/deploy_accounts_svc_plus.yml b/deploy_accounts_svc_plus.yml index b13c4fd..2feb8ca 100644 --- a/deploy_accounts_svc_plus.yml +++ b/deploy_accounts_svc_plus.yml @@ -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) }} diff --git a/roles/vhosts/accounts_service/defaults/main.yml b/roles/vhosts/accounts_service/defaults/main.yml index 40a48e5..51da87f 100644 --- a/roles/vhosts/accounts_service/defaults/main.yml +++ b/roles/vhosts/accounts_service/defaults/main.yml @@ -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 diff --git a/roles/vhosts/accounts_service/tasks/target.yml b/roles/vhosts/accounts_service/tasks/target.yml index c7ac3c5..7fc03a4 100644 --- a/roles/vhosts/accounts_service/tasks/target.yml +++ b/roles/vhosts/accounts_service/tasks/target.yml @@ -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 diff --git a/roles/vhosts/accounts_service/templates/app.env.j2 b/roles/vhosts/accounts_service/templates/app.env.j2 index 72e5f11..d737cc5 100644 --- a/roles/vhosts/accounts_service/templates/app.env.j2 +++ b/roles/vhosts/accounts_service/templates/app.env.j2 @@ -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 }} diff --git a/roles/vhosts/accounts_service/templates/docker-compose.yml.j2 b/roles/vhosts/accounts_service/templates/docker-compose.yml.j2 index 16c94dd..c6cb6e2 100644 --- a/roles/vhosts/accounts_service/templates/docker-compose.yml.j2 +++ b/roles/vhosts/accounts_service/templates/docker-compose.yml.j2 @@ -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