Skip to content

Commit 12176c3

Browse files
authored
Merge pull request #146 from IDunion/github_action
GitHub action to build and push the docker image
2 parents 9833382 + 56a0e4e commit 12176c3

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

.github/workflows/build-docker.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build and Push Docker Image
2+
3+
on: [push]
4+
5+
jobs:
6+
push_to_registry:
7+
name: Push Docker image to GitHub Packages
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check out the repo
11+
uses: actions/checkout@v2
12+
13+
- name: Lowercase repo owner
14+
id: lowercase_repo_owner
15+
uses: ASzc/change-string-case-action@v1
16+
with:
17+
string: ${{ github.repository_owner }}
18+
19+
- name: Prepare labels and tags
20+
id: prep
21+
run: |
22+
DOCKER_IMAGE=ghcr.io/${{ steps.lowercase_repo_owner.outputs.lowercase }}/von-network
23+
VERSION=edge
24+
if [[ $GITHUB_REF == refs/tags/* ]]; then
25+
VERSION=${GITHUB_REF#refs/tags/}
26+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
27+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
28+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
29+
VERSION=pr-${{ github.event.number }}
30+
fi
31+
TAGS="${DOCKER_IMAGE}:${VERSION}"
32+
if [ "${{ github.event_name }}" = "push" ]; then
33+
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
34+
fi
35+
echo ::set-output name=version::${VERSION}
36+
echo ::set-output name=tags::${TAGS}
37+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
38+
39+
- name: Log in to GitHub Container Registry
40+
uses: docker/login-action@v1
41+
with:
42+
registry: ghcr.io
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v1
48+
49+
- name: Build and push von-network image
50+
uses: docker/build-push-action@v2
51+
with:
52+
context: .
53+
push: ${{ github.event_name != 'pull_request' }}
54+
tags: ${{ steps.prep.outputs.tags }}
55+
labels: |
56+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
57+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
58+
org.opencontainers.image.revision=${{ github.sha }}
59+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,6 @@ Pipfile
145145
# Custom TAA
146146
config/aml.json
147147
config/taa.json
148+
149+
# Visual Studio Code
150+
.history

0 commit comments

Comments
 (0)