-
Notifications
You must be signed in to change notification settings - Fork 1
62 lines (53 loc) · 2.06 KB
/
docker-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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.event == 'push' && github.event.workflow_run.conclusion == 'success' }}
environment: build
concurrency:
group: deploy-group-${{ github.ref }}
cancel-in-progress: true
outputs:
branch: "${{ github.event.workflow_run.outputs.branch }}"
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: "${{ github.event.workflow_run.outputs.branch }}"
fetch-depth: 0 # Fetch the entire history to ensure 'HEAD^' is resolvable
- name: Debug github refs
run: |
echo "github.event.workflow_run.outputs.branch = ${{ github.event.workflow_run.outputs.branch }}"
- name: Check if Dockerfile or requirements.txt was changed
id: check_dependencies
run: |
if git diff --name-only "${{ github.event.workflow_run.outputs.branch }}" | 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