From cb5f9133bc3691ebefcd9165a7584a571471263a Mon Sep 17 00:00:00 2001 From: ikhwan Date: Thu, 25 Sep 2025 10:22:17 +0800 Subject: [PATCH 1/2] cicd: modified .gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5c199eb..850701d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ # ---> Ansible *.retry - +/env-file/*.env +/containers/*.container +/vars/*.yml From 217463a8473137b97687717cbcb6710204b888fc Mon Sep 17 00:00:00 2001 From: ikhwan Date: Thu, 25 Sep 2025 10:23:08 +0800 Subject: [PATCH 2/2] cicd: add playbook --- playbook.yml | 15 +++++++++++++++ tasks/main.yml | 29 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 playbook.yml create mode 100644 tasks/main.yml diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..569b6cf --- /dev/null +++ b/playbook.yml @@ -0,0 +1,15 @@ +- hosts: localhost + connection: local + vars_files: + - vars/aws.yml + + environment: + AWS_ACCESS_KEY_ID: "{{ aws_access_key }}" + AWS_SECRET_ACCESS_KEY: "{{ aws_secret_key }}" + AWS_DEFAULT_REGION: "{{ aws_region }}" + AWS_ACCOUNT_ID: "{{ aws_account_id }}" + + tasks: + - name: Include main tasks + include_tasks: tasks/main.yml + \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..2c874ec --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,29 @@ +- name: Authenticate Docker to ECR + shell: > + aws ecr get-login-password --region {{ aws_region }} | podman login --username AWS --password-stdin {{ aws_account_id }}.dkr.ecr.{{ aws_region }}.amazonaws.com + +- name: Pull image from ECR for crm-client + shell: > + podman pull {{ aws_account_id }}.dkr.ecr.{{ aws_region }}.amazonaws.com/prod/crm-client:latest + +- name: Pull image from ECR for crm-server + containers.podman.podman_image: + name: "{{ aws_account_id }}.dkr.ecr.{{ aws_region }}.amazonaws.com/prod/crm-server" + state: present + register: pulled_image_crm_server_result + +- name: Copy crm-server.container file if image was pulled + ansible.builtin.copy: + src: containers/crm-server.container + dest: "{{ ansible_env.HOME }}/.config/containers/systemd/crm-server.container" + when: pulled_image_crm_server_result.changed + register: copy_crm_server_container_file_result + +- name: Restart crm-server systemd service if container file was copied + ansible.builtin.systemd: + name: crm-server + state: restarted + scope: user + daemon_reload: yes + when: copy_crm_server_container_file_result.changed + \ No newline at end of file