This repository was archived by the owner on May 22, 2026. It is now read-only.
forked from inno-devops-labs/DevOps-Core-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (82 loc) · 2.84 KB
/
python-docker.yml
File metadata and controls
85 lines (82 loc) · 2.84 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Python Docker Publish
on:
push:
branches:
- "lab*"
paths:
- app_python/**
- .github/workflows/python-docker.yml
pull_request:
branches:
- master
types:
- closed
paths:
- app_python/**
- .github/workflows/python-docker.yml
jobs:
build-and-push-branch:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Derive lab+sha tag from branch
id: version
run: |
source_branch="${{ github.ref_name }}"
if [[ "$source_branch" =~ ([0-9]+) ]]; then
lab_number="${BASH_REMATCH[1]}"
lab_number=$((10#$lab_number))
short_sha="${GITHUB_SHA::7}"
echo "branch_tag=1.${lab_number}.${short_sha}" >> "$GITHUB_OUTPUT"
echo "branch_dev_tag=1.${lab_number}-dev" >> "$GITHUB_OUTPUT"
else
echo "Failed to extract lab number from branch: $source_branch" >&2
exit 1
fi
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image (branch)
uses: docker/build-push-action@v7
with:
context: ./app_python
file: ./app_python/Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/devops-app-py:${{ steps.version.outputs.branch_tag }}
${{ secrets.DOCKERHUB_USERNAME }}/devops-app-py:${{ steps.version.outputs.branch_dev_tag }}
${{ secrets.DOCKERHUB_USERNAME }}/devops-app-py:dev
build-and-push:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Derive lab version tag from merged branch
id: version
run: |
source_branch="${{ github.event.pull_request.head.ref }}"
if [[ "$source_branch" =~ ([0-9]+) ]]; then
lab_number="${BASH_REMATCH[1]}"
lab_number=$((10#$lab_number))
echo "version_tag=1.${lab_number}" >> "$GITHUB_OUTPUT"
else
echo "Failed to extract lab number from merged branch: $source_branch" >&2
exit 1
fi
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: ./app_python
file: ./app_python/Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/devops-app-py:${{ steps.version.outputs.version_tag }}
${{ secrets.DOCKERHUB_USERNAME }}/devops-app-py:latest