-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (94 loc) · 3.28 KB
/
build-container.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
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
106
107
---
name: docker-hub build and push
on:
workflow_call:
inputs:
container-tag:
type: string
required: true
description: 'The tag to use for the container'
env:
fail-fast: true
permissions:
contents: write
issues: write
jobs:
get-release:
name: Get latest release tag
runs-on: ubuntu-latest
outputs:
app_version: ${{ steps.get_release_tag.outputs.app_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Get the last tag via git and store in var
id: get_release_tag
run: |
APP_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "${APP_VERSION}"
echo "app_version=${APP_VERSION}" >> ${GITHUB_OUTPUT}
docker-hub:
needs: get-release
name: Build and push to DockerHub
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: show app_version from release job
env:
RELEASE_TAG: ${{ needs.get-release.outputs.app_version }}
run: |
echo "Delivered release tag is ${RELEASE_TAG} (local var)"
echo "Delivered release tag is ${{ needs.get-release.outputs.app_version }} (from needs)"
echo "Delivered release tag is ${{ env.RELEASE_TAG }} (from env)"
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Extract metadata (tags, labels) for development
id: meta-dev
uses: docker/metadata-action@v5
if: ${{ inputs.container-tag != 'latest' }}
env:
RELEASE_TAG: ${{ needs.get-release.outputs.app_version }}
with:
images: ${{ secrets.DOCKER_USERNAME }}/${{ vars.DOCKER_PROJECT_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=${{ inputs.container-tag }}
- name: Extract metadata (tags, labels) for latest release
id: meta-latest
uses: docker/metadata-action@v5
if: ${{ inputs.container-tag == 'latest' }}
env:
RELEASE_TAG: ${{ needs.get-release.outputs.app_version }}
with:
images: ${{ secrets.DOCKER_USERNAME }}/${{ vars.DOCKER_PROJECT_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=${{ env.RELEASE_TAG }}
type=raw,value=${{ inputs.container-tag }}
- name: Build and push for development
uses: docker/build-push-action@v6
if: ${{ inputs.container-tag != 'latest' }}
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta-dev.outputs.tags }}
labels: ${{ steps.meta-dev.outputs.labels }}
- name: Build and push for latest
uses: docker/build-push-action@v6
if: ${{ inputs.container-tag == 'latest' }}
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta-latest.outputs.tags }}
labels: ${{ steps.meta-latest.outputs.labels }}