-
Notifications
You must be signed in to change notification settings - Fork 1
105 lines (90 loc) · 3.42 KB
/
docker_build.yml
File metadata and controls
105 lines (90 loc) · 3.42 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Docker Build
# Although we only want to push docker images to docker hub on pushes to main (that result from
# pull requests), we also subscribe to the pull request event itself. In this case we won't upload
# the image, but still build it so we are noticed if it fails.
on:
# A successful merge request to main will result into a push to main.
push:
branches:
- "main"
pull_request:
branches:
- "main"
# For manual triggering
workflow_dispatch:
permissions:
contents: read
jobs:
version:
runs-on: ubuntu-latest
permissions:
contents: write # so we're allowed to push the new tag
outputs:
SemVer: ${{ steps.gitversion.outputs.SemVer }}
Major: ${{ steps.gitversion.outputs.Major }}
Minor: ${{ steps.gitversion.outputs.Minor }}
Patch: ${{ steps.gitversion.outputs.Patch }}
steps:
- name: Checkout git repo
uses: actions/checkout@v6
with:
fetch-depth: 0 # This is needed for GitVersion not to crash
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3
with:
versionSpec: "5.12.0"
- name: Determine Version
id: gitversion # id to later be referenced
uses: gittools/actions/gitversion/execute@v3
- name: Create version tag
if: github.event_name != 'pull_request'
run: |
git config --global user.email "github_pipeline@fairagro.net"
git config --global user.name "Github Pipeline"
git tag -a v${{ steps.gitversion.outputs.SemVer }} -m "release ${{ steps.gitversion.outputs.SemVer }}"
git push origin v${{ steps.gitversion.outputs.SemVer }}
docker_build:
runs-on: ubuntu-latest
needs: version
env:
PYTHON_VERSION: 3.12
steps:
- name: Checkout git repo
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: zalf/fairagro_basic_middleware
tags: |
type=semver,pattern={{version}},value=${{ needs.version.outputs.SemVer }}
type=raw,value=${{ needs.version.outputs.Major }}.${{ needs.version.outputs.Minor }}
type=raw,value=${{ needs.version.outputs.Major }}
- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
load: true
tags: middleware:test
labels: ${{ steps.metadata.outputs.labels }} # we need the labels as they're checked for
build-args: python_version=${{ env.PYTHON_VERSION }}
- name: Test image
uses: plexsystems/container-structure-test-action@v0.3.0
with:
image: middleware:test
config: test/container-structure-test/container-structure-test-config.yml
# Secrets are managed within the github GUI
- name: Log in to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v6
with:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
build-args: python_version=${{ env.PYTHON_VERSION }}