-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (93 loc) · 2.98 KB
/
workflow-build-image.yaml
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: build-image
on:
workflow_call:
inputs:
registry:
required: true
type: string
image-name:
required: true
type: string
context:
required: false
type: string
default: .
containerfile:
required: false
type: string
default: ./Containerfile
tag-base:
required: false
type: string
tag-suffix:
required: false
type: string
default: ""
push-latest:
required: false
type: boolean
default: false
secrets:
registry-username:
required: true
registry-password:
required: true
hf-token:
required: false
outputs:
target_tag:
value: ${{ jobs.build-image.outputs.target_tag }}
jobs:
build-image:
name: Build Image
runs-on: ubuntu-latest
outputs:
target_tag: ${{ steps.version.outputs.date_tag }}
steps:
- name: Checkout Repository
id: checkout
uses: actions/checkout@v4
# - name: downgrade docker
# run: |
# apt-cache madison docker.io
# sudo apt-get remove containerd.io
# sudo apt-get install docker.io=24.0.7-0ubuntu2~22.04.1
- name: Create tags
id: version
run: |
PYPROJECT_FILE="${{ inputs.context }}/pyproject.toml"
if [ -f ${PYPROJECT_FILE} ]; then
VERSION=$(awk -F' = ' '/^version/ {gsub(/"/, "", $2); print $2}' ${PYPROJECT_FILE} | tr -d '"')
echo "version=$VERSION" | tee -a $GITHUB_OUTPUT
fi
MAIN_TAG=${{ inputs.tag-base }}${VERSION}${{ inputs.tag-suffix }}
echo "main_tag=$MAIN_TAG" | tee -a $GITHUB_OUTPUT
DATE=$(date -u +'%Y%m%dt%H%Mz')
echo "date=${DATE}" | tee -a $GITHUB_OUTPUT
DATE_TAG=${MAIN_TAG}-${DATE}
echo "date_tag=${DATE_TAG}" | tee -a $GITHUB_OUTPUT
TAGS="${MAIN_TAG} ${DATE_TAG}"
if ${{ inputs.push-latest }}; then
LATEST_TAG="latest${{ inputs.tag-suffix }}"
echo "latest_tag=${LATEST_TAG}" | tee -a $GITHUB_OUTPUT
TAGS="${TAGS} ${LATEST_TAG}"
fi
echo "tags=${TAGS}" | tee -a $GITHUB_OUTPUT
- name: Setup and Build
id: build_image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ inputs.image-name }}
tags: ${{ steps.version.outputs.tags }}
context: ${{ inputs.context }}
containerfiles: ${{ inputs.context }}/${{ inputs.containerfile }}
build-args: HF_TOKEN=${{ secrets.hf-token }}
- name: Push-Image
id: push-to-registry
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ inputs.registry }}
username: ${{ secrets.registry-username }}
password: ${{ secrets.registry-password }}