Skip to content

Commit dd4a998

Browse files
authored
Build and push container images (#3)
1 parent 84c1ca7 commit dd4a998

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

.dockerignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
22
# Ignore build and test binaries.
3-
bin/
3+
!api/
4+
!cmd/
5+
!examples/
6+
!internal/
7+
!go.mod
8+
!go.sum

.github/workflows/build.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
6+
env:
7+
IMG_REGISTRY: ghcr.io/slyngdk/
8+
IMG_NAME_CONTROLLER: nodedrain
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Setup Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.mod
21+
22+
- name: Login to GitHub Container Registry
23+
if: github.ref == 'refs/heads/main' || github.ref_type == 'tag'
24+
uses: docker/login-action@v3
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Build image
31+
id: build_image
32+
run: |
33+
export IMG_TAG=ci-${{ github.ref_name }}
34+
if [[ "${{ github.ref_type }}" == "branch" && "${{ github.ref_name }}" == "main" ]]; then
35+
export IMG_TAG=latest
36+
elif [[ "${{ github.ref_type }}" == "tag" && "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
37+
export IMG_TAG=$(echo -n "${{ github.ref_name }}" | sed 's/^v//g')
38+
fi
39+
echo "IMG_TAG=${IMG_TAG}" >> $GITHUB_OUTPUT
40+
make docker-build
41+
42+
- name: Push image
43+
if: github.ref == 'refs/heads/main' || github.ref_type == 'tag'
44+
env:
45+
IMG_TAG: ${{ steps.build_image.outputs.IMG_TAG }}
46+
run: |
47+
if [[ "${{ github.ref_type }}" == "tag" && "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit 0
48+
make docker-push

0 commit comments

Comments
 (0)