feat(cd): Added ansible
This commit is contained in:
1 parent
e587346267
commit
9bf23d55d0
2 files changed
+36
No files matched your search
@@ -51,3 +51,24 @@ jobs:
|
||||
labels: ${{ steps.tags.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
deploy:
|
||||
needs: docker-build-and-push
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install Ansible
|
||||
run: apt-get update && apt-get install -y ansible
|
||||
- name: Set up SSH key
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
|
||||
chmod 600 ~/.ssh/deploy_key
|
||||
- name: Trust server host key
|
||||
run: |
|
||||
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
|
||||
- name: Run Ansible playbook
|
||||
run: |
|
||||
ansible-playbook -i "${{ secrets.SERVER_IP }}," ansible/restart_compose.yml \
|
||||
--user "${{ secrets.SERVER_USER }}" \
|
||||
--private-key ~/.ssh/deploy_key
|
||||
@@ -0,0 +1,15 @@
|
||||
- name: Restart Docker Compose services
|
||||
hosts: all
|
||||
# become: yes # <-- больше не нужно, т.к. пользователь уже имеет права Docker
|
||||
tasks:
|
||||
- name: docker compose down
|
||||
ansible.builtin.shell:
|
||||
cmd: docker compose down
|
||||
chdir: /etc/compose/resume
|
||||
- name: prune system
|
||||
ansible.builtin.shell:
|
||||
cmd: docker system prune -a -f
|
||||
- name: docker compose up -d
|
||||
ansible.builtin.shell:
|
||||
cmd: docker compose up -d
|
||||
chdir: /etc/compose/pvh
|
||||
Reference in new issue
Block a user