forked from kubernetes-for-developers/kfd-flask
-
Notifications
You must be signed in to change notification settings - Fork 1
62 lines (51 loc) · 1.89 KB
/
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
name: Build image
on:
workflow_call:
outputs:
image:
description: "Image uri"
value: ${{ jobs.push.outputs.image }}
tag:
description: "Image tag"
value: ${{ jobs.push.outputs.tag }}
env:
IMAGE_NAME: kfd-flask
jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
outputs:
image: ${{ steps.build.outputs.image }}
tag: ${{ steps.build.outputs.tag }}
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Build and push image
id: build
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker buildx build . --file Dockerfile --tag $IMAGE_ID:$VERSION \
--label "runnumber=${GITHUB_RUN_ID}" \
--label "org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}" \
--platform linux/amd64,linux/arm64 --push
echo "image=$IMAGE_ID" >> $GITHUB_OUTPUT
echo "tag=$VERSION" >> $GITHUB_OUTPUT