Deploy billing-service from build artifact
This commit is contained in:
parent
97d49eaf39
commit
c0f1a1c2ee
@ -3,9 +3,12 @@
|
|||||||
gather_facts: true
|
gather_facts: true
|
||||||
become: true
|
become: true
|
||||||
vars:
|
vars:
|
||||||
billing_service_source_dir: >-
|
billing_service_binary_artifact: >-
|
||||||
{{ lookup('ansible.builtin.env', 'BILLING_SERVICE_SOURCE_DIR')
|
{{ lookup('ansible.builtin.env', 'BILLING_SERVICE_BINARY_ARTIFACT')
|
||||||
| default(playbook_dir ~ '/../billing-service', true) }}
|
| default('', true) }}
|
||||||
|
billing_service_image_ref: >-
|
||||||
|
{{ lookup('ansible.builtin.env', 'BILLING_SERVICE_IMAGE_REF')
|
||||||
|
| default('', true) }}
|
||||||
billing_service_exporter_base_url: >-
|
billing_service_exporter_base_url: >-
|
||||||
{{ lookup('ansible.builtin.env', 'EXPORTER_BASE_URL')
|
{{ lookup('ansible.builtin.env', 'EXPORTER_BASE_URL')
|
||||||
| default('http://127.0.0.1:8080', true) }}
|
| default('http://127.0.0.1:8080', true) }}
|
||||||
@ -39,6 +42,35 @@
|
|||||||
{{ lookup('ansible.builtin.env', 'INITIAL_BALANCE')
|
{{ lookup('ansible.builtin.env', 'INITIAL_BALANCE')
|
||||||
| default('0', true) }}
|
| default('0', true) }}
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
|
- name: Validate BILLING_SERVICE_BINARY_ARTIFACT is present
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- billing_service_binary_artifact | length > 0
|
||||||
|
fail_msg: "BILLING_SERVICE_BINARY_ARTIFACT must be exported before running this playbook."
|
||||||
|
success_msg: "BILLING_SERVICE_BINARY_ARTIFACT found"
|
||||||
|
- name: Validate BILLING_SERVICE_BINARY_ARTIFACT exists
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ billing_service_binary_artifact }}"
|
||||||
|
register: billing_service_binary_artifact_stat
|
||||||
|
delegate_to: localhost
|
||||||
|
become: false
|
||||||
|
run_once: true
|
||||||
|
- name: Assert BILLING_SERVICE_BINARY_ARTIFACT exists on controller
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- billing_service_binary_artifact_stat.stat.exists
|
||||||
|
- billing_service_binary_artifact_stat.stat.isreg
|
||||||
|
fail_msg: "BILLING_SERVICE_BINARY_ARTIFACT must point to an existing binary artifact."
|
||||||
|
success_msg: "BILLING_SERVICE_BINARY_ARTIFACT exists"
|
||||||
|
delegate_to: localhost
|
||||||
|
become: false
|
||||||
|
run_once: true
|
||||||
|
- name: Validate BILLING_SERVICE_IMAGE_REF is present
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- billing_service_image_ref | length > 0
|
||||||
|
fail_msg: "BILLING_SERVICE_IMAGE_REF must be exported before running this playbook."
|
||||||
|
success_msg: "BILLING_SERVICE_IMAGE_REF found"
|
||||||
- name: Validate DATABASE_URL is present
|
- name: Validate DATABASE_URL is present
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
---
|
---
|
||||||
billing_service_source_dir: "{{ playbook_dir }}/../billing-service"
|
|
||||||
billing_service_app_dir: "/opt/billing-service"
|
billing_service_app_dir: "/opt/billing-service"
|
||||||
billing_service_go_version: "1.25.1"
|
|
||||||
billing_service_go_root: "/usr/local/go"
|
|
||||||
billing_service_go_bin: "{{ billing_service_go_root }}/bin/go"
|
|
||||||
billing_service_binary_name: "billing-service"
|
billing_service_binary_name: "billing-service"
|
||||||
billing_service_binary_path: "/usr/local/bin/{{ billing_service_binary_name }}"
|
billing_service_binary_path: "/usr/local/bin/{{ billing_service_binary_name }}"
|
||||||
|
billing_service_binary_artifact: ""
|
||||||
|
billing_service_image_ref: ""
|
||||||
billing_service_service_name: "billing-service"
|
billing_service_service_name: "billing-service"
|
||||||
billing_service_service_description: "billing-service service"
|
billing_service_service_description: "billing-service service"
|
||||||
billing_service_user: "root"
|
billing_service_user: "root"
|
||||||
|
|||||||
@ -1,45 +1,3 @@
|
|||||||
---
|
|
||||||
- name: Map Go architecture
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
billing_service_go_arch: >-
|
|
||||||
{{ 'arm64' if ansible_architecture in ['aarch64', 'arm64'] else 'amd64' }}
|
|
||||||
|
|
||||||
- name: Ensure billing-service build prerequisites are installed
|
|
||||||
ansible.builtin.apt:
|
|
||||||
name:
|
|
||||||
- curl
|
|
||||||
- ca-certificates
|
|
||||||
- tar
|
|
||||||
- rsync
|
|
||||||
state: present
|
|
||||||
update_cache: true
|
|
||||||
|
|
||||||
- name: Check installed Go version
|
|
||||||
ansible.builtin.command: "{{ billing_service_go_bin }} version"
|
|
||||||
register: billing_service_go_version_check
|
|
||||||
changed_when: false
|
|
||||||
failed_when: false
|
|
||||||
|
|
||||||
- name: Download Go toolchain archive
|
|
||||||
ansible.builtin.get_url:
|
|
||||||
url: "https://go.dev/dl/go{{ billing_service_go_version }}.linux-{{ billing_service_go_arch }}.tar.gz"
|
|
||||||
dest: "/tmp/go{{ billing_service_go_version }}.linux-{{ billing_service_go_arch }}.tar.gz"
|
|
||||||
mode: "0644"
|
|
||||||
when: billing_service_go_version_check.rc != 0 or ('go' ~ billing_service_go_version) not in billing_service_go_version_check.stdout
|
|
||||||
|
|
||||||
- name: Remove previous Go installation
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ billing_service_go_root }}"
|
|
||||||
state: absent
|
|
||||||
when: billing_service_go_version_check.rc != 0 or ('go' ~ billing_service_go_version) not in billing_service_go_version_check.stdout
|
|
||||||
|
|
||||||
- name: Install Go toolchain
|
|
||||||
ansible.builtin.unarchive:
|
|
||||||
src: "/tmp/go{{ billing_service_go_version }}.linux-{{ billing_service_go_arch }}.tar.gz"
|
|
||||||
dest: "/usr/local"
|
|
||||||
remote_src: true
|
|
||||||
when: billing_service_go_version_check.rc != 0 or ('go' ~ billing_service_go_version) not in billing_service_go_version_check.stdout
|
|
||||||
|
|
||||||
- name: Create billing-service directories
|
- name: Create billing-service directories
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
@ -51,22 +9,13 @@
|
|||||||
- "{{ billing_service_app_dir }}"
|
- "{{ billing_service_app_dir }}"
|
||||||
- "{{ billing_service_env_dir }}"
|
- "{{ billing_service_env_dir }}"
|
||||||
|
|
||||||
- name: Sync billing-service source tree
|
- name: Deploy billing-service binary artifact
|
||||||
ansible.posix.synchronize:
|
ansible.builtin.copy:
|
||||||
src: "{{ billing_service_source_dir }}/"
|
src: "{{ billing_service_binary_artifact }}"
|
||||||
dest: "{{ billing_service_app_dir }}/"
|
dest: "{{ billing_service_binary_path }}"
|
||||||
delete: true
|
owner: "{{ billing_service_user }}"
|
||||||
notify: Restart billing-service
|
group: "{{ billing_service_group }}"
|
||||||
|
mode: "0755"
|
||||||
- name: Build billing-service binary
|
|
||||||
ansible.builtin.command: >-
|
|
||||||
{{ billing_service_go_bin }} build -buildvcs=false -o {{ billing_service_binary_path }} ./cmd/billing-service
|
|
||||||
args:
|
|
||||||
chdir: "{{ billing_service_app_dir }}"
|
|
||||||
environment:
|
|
||||||
GOROOT: "{{ billing_service_go_root }}"
|
|
||||||
PATH: "{{ billing_service_go_root }}/bin:{{ ansible_env.PATH }}"
|
|
||||||
GOTOOLCHAIN: local
|
|
||||||
notify: Restart billing-service
|
notify: Restart billing-service
|
||||||
|
|
||||||
- name: Ensure billing-service binary permissions
|
- name: Ensure billing-service binary permissions
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
IMAGE={{ billing_service_image_ref }}
|
||||||
EXPORTER_BASE_URL={{ billing_service_exporter_base_url }}
|
EXPORTER_BASE_URL={{ billing_service_exporter_base_url }}
|
||||||
EXPORTER_SOURCES_JSON={{ billing_service_exporter_sources_json }}
|
EXPORTER_SOURCES_JSON={{ billing_service_exporter_sources_json }}
|
||||||
INTERNAL_SERVICE_TOKEN={{ billing_service_internal_service_token }}
|
INTERNAL_SERVICE_TOKEN={{ billing_service_internal_service_token }}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user