Skip to content

Commit 5aa531f

Browse files
Feature/add docker build (#11)
* Add basic Dockerfile and actions workflow * Add workflow that releases binaries
1 parent 4968811 commit 5aa531f

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build and Publish Go Binary
2+
on:
3+
push:
4+
branches:
5+
- 'release/*'
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
os: [linux, darwin, windows]
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: '1.20'
20+
21+
- name: Build Go binaries
22+
run: |
23+
if [ ${{ matrix.os }} == "windows" ]; then
24+
CGO_ENABLED=0 GOOS=${{ matrix.os }} go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o tf-profile.exe .
25+
else
26+
CGO_ENABLED=0 GOOS=${{ matrix.os }} go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o tf-profile .
27+
fi
28+
29+
- name: Extract release version from branch name
30+
id: release_version
31+
run: echo "::set-output name=version::${GITHUB_REF##*/}"
32+
33+
- name: Create artifact
34+
uses: actions/upload-artifact@v2
35+
with:
36+
name: tf-profile-v${{ steps.release_version.outputs.version }}-${{ matrix.os }}
37+
path: |
38+
./tf-profile
39+
./tf-profile.exe
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Build and push Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- 'release/*'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
15+
- name: Login to Docker Hub
16+
uses: docker/login-action@v1
17+
with:
18+
username: qbruynseraede
19+
password: ${{ secrets.DOCKER_PASSWORD }}
20+
21+
- name: Extract release version from branch name
22+
id: release_version
23+
run: echo "::set-output name=version::${GITHUB_REF##*/}"
24+
25+
- name: Build Docker image
26+
run: >
27+
docker build
28+
-t qbruynseraede/tf-profile:${{ steps.release_version.outputs.version }}
29+
-f build/Dockerfile
30+
.
31+
32+
- name: Push Docker image
33+
run: docker push qbruynseraede/tf-profile:${{ steps.release_version.outputs.version }}
34+

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1

build/Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Build the application from source
2+
FROM golang:1.20 AS build
3+
4+
WORKDIR /app
5+
6+
COPY go.mod go.sum ./
7+
RUN go mod download
8+
9+
COPY *.go ./
10+
COPY ./pkg/ ./pkg/
11+
COPY ./cmd ./cmd
12+
13+
RUN find ./
14+
15+
RUN CGO_ENABLED=0 GOOS=linux go build -o /tf-profile
16+
17+
# Run the tests in the container
18+
FROM build AS run-test-stage
19+
COPY ./test ./test
20+
RUN go test -v ./...
21+
22+
# Deploy the application binary into a lean image
23+
FROM gcr.io/distroless/base-debian11 AS build-release-stage
24+
25+
WORKDIR /
26+
27+
COPY --from=build /tf-profile /tf-profile
28+
29+
USER nonroot:nonroot
30+
31+
ENTRYPOINT ["/tf-profile"]

0 commit comments

Comments
 (0)