From 0fd738a9aa48ae26fe9bef5cceed179b2e3a341e Mon Sep 17 00:00:00 2001 From: okx-code Date: Tue, 5 Nov 2024 19:26:56 +0000 Subject: [PATCH] fix stacks and add faster minecraft deployment --- .../ansible_update_server_minecraft.yml | 48 +++++++++++++++++++ ansible/playbooks/update-server-minecraft.yml | 22 +++++++++ ansible/tasks/deploy/stacks.yml | 15 +----- 3 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/ansible_update_server_minecraft.yml create mode 100644 ansible/playbooks/update-server-minecraft.yml diff --git a/.github/workflows/ansible_update_server_minecraft.yml b/.github/workflows/ansible_update_server_minecraft.yml new file mode 100644 index 000000000..847e90433 --- /dev/null +++ b/.github/workflows/ansible_update_server_minecraft.yml @@ -0,0 +1,48 @@ +name: 🏗️ Ansible | Update Server (Minecraft) +on: + workflow_dispatch: + inputs: + environment: + description: 'Environment to Update' + type: environment + required: true + default: Test + +jobs: + update-server: + runs-on: ubuntu-latest + environment: ${{inputs.environment}} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: ☕ Setup Java + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: 🐘 Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: 🐘 Gradle Build + run: CI=true ./gradlew :ansible:build + + - name: Inject secrets + run: 'echo "$SECRETS_YML" > variables/secrets.yml' + shell: bash + working-directory: ./ansible + env: + SECRETS_YML: ${{secrets.SECRETS_YML}} + SUDO_PASSWORD: ${{secrets.SUDO_PASSWORD}} + + - name: Update Server (Minecraft) + uses: dawidd6/action-ansible-playbook@v2 + with: + playbook: ansible/playbooks/update-server-minecraft.yml + requirements: ansible/requirements.yml + key: ${{secrets.SSH_PRIVATE_KEY}} + known_hosts: ${{secrets.SSH_KNOWN_HOSTS}} + options: | + --inventory ./ansible/inventories/civmc-${{inputs.environment}}.yml + -e "ansible_become_password=${{secrets.SUDO_PASSWORD}}" diff --git a/ansible/playbooks/update-server-minecraft.yml b/ansible/playbooks/update-server-minecraft.yml new file mode 100644 index 000000000..9696625ec --- /dev/null +++ b/ansible/playbooks/update-server-minecraft.yml @@ -0,0 +1,22 @@ +- name: Update Server (Minecraft) + hosts: all + become: true + + tasks: + - name: Update Serer | Include Preflight + include_tasks: ../tasks/preflight-checks.yml + + - name: Update Server | Expand setting + include_tasks: ../tasks/expand-setting.yml + + - name: Update Server | Include Stop Tasks + include_tasks: + file: '../tasks/stop-server.yml' + + - name: Update Server | Include Deployment Tasks + include_tasks: + file: '../tasks/deploy/{{deploy_task}}.yml' + loop: + - stacks + loop_control: + loop_var: deploy_task diff --git a/ansible/tasks/deploy/stacks.yml b/ansible/tasks/deploy/stacks.yml index 6476dab95..96978ab04 100644 --- a/ansible/tasks/deploy/stacks.yml +++ b/ansible/tasks/deploy/stacks.yml @@ -54,20 +54,6 @@ - { path: 'minecraft/proxy-config', enabled: setting.minecraft.enabled } - { path: 'minecraft/proxy-plugins', enabled: setting.minecraft.enabled } -- name: Deploy Stacks | Copy Files - become: false - when: - - "'swarm_manager' in group_names" - - item.enabled - ansible.posix.synchronize: - src: '{{item.file}}' - dest: '~/stacks/{{item.target}}' - loop: - - { file: '../../files/paper-config', target: 'minecraft', enabled: setting.minecraft.enabled } - - { file: '../../files/proxy-config', target: 'minecraft', enabled: setting.minecraft.enabled } - - { file: '../../build/paper-plugins', target: 'minecraft', enabled: setting.minecraft.enabled } - - { file: '../../build/proxy-plugins', target: 'minecraft', enabled: setting.minecraft.enabled } - - name: Deploy Stacks | Synchronize Files become: false when: @@ -76,6 +62,7 @@ ansible.posix.synchronize: src: '{{item.file}}' dest: '~/stacks/{{item.target}}' + delete: true loop: - { file: '../../files/paper-config', target: 'minecraft', enabled: setting.minecraft.enabled } - { file: '../../files/proxy-config', target: 'minecraft', enabled: setting.minecraft.enabled }