Skip to content

Commit b85093d

Browse files
authored
added docker-publish
1 parent 13bf2fc commit b85093d

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Docker Build
2+
#
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- '*'
9+
#
10+
jobs:
11+
docker-build:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
packages: write
16+
steps:
17+
# Checkout the repository to the GitHub Actions runner
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
21+
# Repo metadata
22+
- name: Repo metadata
23+
id: repo
24+
uses: actions/github-script@v4
25+
with:
26+
script: |
27+
const repo = await github.repos.get(context.repo)
28+
return repo.data
29+
#
30+
- name: Extract Git hash
31+
id: git
32+
run: echo "GIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
33+
#
34+
# Prepare variables
35+
- name: Prepare
36+
id: prep
37+
run: |
38+
REG=ghcr.io
39+
IMAGE=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
40+
DOCKER_IMAGE=${REG}/${IMAGE}
41+
VERSION=nool-
42+
if [ "${{ github.event_name }}" = "schedule" ]; then
43+
VERSION=nightly
44+
elif [[ $GITHUB_REF == refs/tags/* ]]; then
45+
VERSION=${GITHUB_REF#refs/tags/}
46+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
47+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
48+
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
49+
VERSION=latest
50+
fi
51+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
52+
VERSION=pr-${{ github.event.number }}
53+
fi
54+
VERSION=${{ env.GIT_HASH }}
55+
TAGS="${DOCKER_IMAGE}:${VERSION}"
56+
echo ::set-output name=version::${VERSION}
57+
echo ::set-output name=tags::${TAGS}
58+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
59+
# Set up Buildx env
60+
- name: Set up Docker Buildx
61+
uses: docker/setup-buildx-action@v2
62+
63+
# Login
64+
- name: Login to GitHub Container Registry
65+
uses: docker/login-action@v2
66+
with:
67+
registry: ghcr.io
68+
username: ${{ github.actor }}
69+
password: ${{ secrets.GITHUB_TOKEN }}
70+
71+
# Build image and push to registry
72+
- name: Build and push
73+
uses: docker/build-push-action@v4
74+
with:
75+
context: .
76+
file: ./docker/Dockerfile
77+
platforms: linux/amd64
78+
push: true
79+
tags: ${{ steps.prep.outputs.tags }}
80+
labels: |
81+
org.opencontainers.image.title=${{ fromJson(steps.repo.outputs.result).name }}
82+
org.opencontainers.image.description=${{ fromJson(steps.repo.outputs.result).description }}
83+
org.opencontainers.image.url=${{ fromJson(steps.repo.outputs.result).html_url }}
84+
org.opencontainers.image.source=${{ fromJson(steps.repo.outputs.result).html_url }}
85+
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
86+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
87+
org.opencontainers.image.revision=${{ github.sha }}
88+
org.opencontainers.image.licenses=${{ fromJson(steps.repo.outputs.result).license.spdx_id }}

0 commit comments

Comments
 (0)