Skip to content

Build and deploy

Build and deploy #7

Workflow file for this run

name: Build and Push Docker Image
on:
workflow_run:
workflows: ["Django tests"]
types:
- completed
branches:
- dev
- main
jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
environment: build
concurrency:
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