Skip to content

Commit

Permalink
Consolidate deployment workflows to run in series
Browse files Browse the repository at this point in the history
  • Loading branch information
neoformit committed Oct 8, 2024
1 parent 30035fa commit 76af25c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 63 deletions.
50 changes: 0 additions & 50 deletions .github/workflows/ansible-deploy-dev.yml

This file was deleted.

17 changes: 11 additions & 6 deletions .github/workflows/ansible-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ name: Deploy to prod server with Ansible playbook

on:
workflow_run:
workflows: ["Django tests"]
workflows: ["Build and Push Docker Image"]
types:
- completed
branches:
- dev
- main

jobs:
deploy:
runs-on: ubuntu-latest
environment: deployment
if: ${{ github.event.workflow_run.conclusion == 'success' }}
concurrency:
group: docker-build-group
cancel-in-progress: false
group: deploy-group
cancel-in-progress: true

steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
ref: main
ref: ${{ github.ref }}

- name: Set up Python
uses: actions/setup-python@v2
Expand All @@ -42,8 +42,13 @@ jobs:
- name: Run Ansible Playbook
run: |
if [ $GITHUB_REF == "refs/heads/dev" ]; then
PLAYBOOK=dev.yml
else
PLAYBOOK=prod.yml
fi
cd ansible
ansible-playbook -i hosts prod.yml --tags update
ansible-playbook -i hosts $PLAYBOOK --tags update
env:
ANSIBLE_HOST_KEY_CHECKING: 'False'
ANSIBLE_REMOTE_USER: ${{ secrets.SSH_USER }}
Expand Down
30 changes: 23 additions & 7 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
name: Build and Push Docker Image

on:
push:
workflow_run:
workflows: ["Django tests"]
types:
- completed
branches:
- main
- dev
paths:
- Dockerfile
- requirements.txt
- main

jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
environment: build
concurrency:
group: docker-build-group
cancel-in-progress: false
group: deploy-group
cancel-in-progress: true

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Check if Dockerfile or requirements.txt was changed
id: check_dependencies
run: |
if git diff --name-only HEAD^ HEAD | grep -q -e 'Dockerfile' -e 'requirements.txt'; then
echo "Dockerfile or requirements.txt changed"
echo "::set-output name=updated::true"
else
echo "Dockerfile or requirements.txt not changed"
echo "::set-output name=updated::false"
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
if: steps.check_dependencies.outputs.updated == 'true'

- name: Log in to DockerHub
uses: docker/login-action@v2
if: steps.check_dependencies.outputs.updated == 'true'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build Docker image
if: steps.check_dependencies.outputs.updated == 'true'
run: docker build -t ${{ secrets.DOCKER_IMAGE }}:latest .

- name: Push Docker image
if: steps.check_dependencies.outputs.updated == 'true'
run: docker push ${{ secrets.DOCKER_IMAGE }}:latest

0 comments on commit 76af25c

Please sign in to comment.