Skip to content

Commit

Permalink
Feature/add docker build (#11)
Browse files Browse the repository at this point in the history
* Add basic Dockerfile and actions workflow
* Add workflow that releases binaries
  • Loading branch information
QuintenBruynseraede authored Apr 16, 2023
1 parent 4968811 commit 5aa531f
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build-release-artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build and Publish Go Binary
on:
push:
branches:
- 'release/*'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, darwin, windows]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.20'

- name: Build Go binaries
run: |
if [ ${{ matrix.os }} == "windows" ]; then
CGO_ENABLED=0 GOOS=${{ matrix.os }} go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o tf-profile.exe .
else
CGO_ENABLED=0 GOOS=${{ matrix.os }} go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o tf-profile .
fi
- name: Extract release version from branch name
id: release_version
run: echo "::set-output name=version::${GITHUB_REF##*/}"

- name: Create artifact
uses: actions/upload-artifact@v2
with:
name: tf-profile-v${{ steps.release_version.outputs.version }}-${{ matrix.os }}
path: |
./tf-profile
./tf-profile.exe
34 changes: 34 additions & 0 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build and push Docker image

on:
push:
branches:
- 'release/*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: qbruynseraede
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract release version from branch name
id: release_version
run: echo "::set-output name=version::${GITHUB_REF##*/}"

- name: Build Docker image
run: >
docker build
-t qbruynseraede/tf-profile:${{ steps.release_version.outputs.version }}
-f build/Dockerfile
.
- name: Push Docker image
run: docker push qbruynseraede/tf-profile:${{ steps.release_version.outputs.version }}

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
31 changes: 31 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Build the application from source
FROM golang:1.20 AS build

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY *.go ./
COPY ./pkg/ ./pkg/
COPY ./cmd ./cmd

RUN find ./

RUN CGO_ENABLED=0 GOOS=linux go build -o /tf-profile

# Run the tests in the container
FROM build AS run-test-stage
COPY ./test ./test
RUN go test -v ./...

# Deploy the application binary into a lean image
FROM gcr.io/distroless/base-debian11 AS build-release-stage

WORKDIR /

COPY --from=build /tf-profile /tf-profile

USER nonroot:nonroot

ENTRYPOINT ["/tf-profile"]

0 comments on commit 5aa531f

Please sign in to comment.