-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add basic Dockerfile and actions workflow * Add workflow that releases binaries
- Loading branch information
1 parent
4968811
commit 5aa531f
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |