Skip to content

Commit

Permalink
feat: go build cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Oct 14, 2024
1 parent 83fc66f commit 7682e88
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build-dev-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ jobs:
type=ref,event=pr
type=raw,value=latest-{{date 'YYYYMMDDHHmmss'}}-{{sha}}
- name: Go Build Cache for Docker
uses: actions/cache@v4
with:
path: go-build-cache
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
Expand All @@ -55,3 +61,5 @@ jobs:
platforms: |
linux/amd64
linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
8 changes: 8 additions & 0 deletions .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Go Build Cache for Docker
uses: actions/cache@v4
with:
path: go-build-cache
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
Expand All @@ -53,6 +59,8 @@ jobs:
platforms: |
linux/amd64
linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

release-helm:
runs-on: ubuntu-latest
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
FROM --platform=$BUILDPLATFORM golang:1.23-alpine3.20 as builder
FROM --platform=$BUILDPLATFORM golang:1.23-alpine3.20 AS builder
RUN go env -w GOMODCACHE=/root/.cache/go-build
# Define target arch variables so we can use them while crosscompiling, will be set automatically
ARG TARGETOS
ARG TARGETARCH
WORKDIR /go/src/

# get dependencies
COPY go.mod go.sum ./
RUN go mod download
RUN --mount=type=cache,target=/root/.cache/go-build go mod download

# copy code
COPY . .

# Build project
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -ldflags "-s -w" -a -installsuffix cgo -o /radix-prometheus-proxy
RUN --mount=type=cache,target=/root/.cache/go-build GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -ldflags "-s -w" -a -installsuffix cgo -o /radix-prometheus-proxy

# Final stage, ref https://github.com/GoogleContainerTools/distroless/blob/main/base/README.md for distroless
FROM gcr.io/distroless/static
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,32 @@ Currently this exports uptime statistics using the `probe_success` metric from p
## How we work

Commits to the main branch must follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) and uses Release Please to create new versions.

# TODO:

- Manually patch helm chart based on please-release output
- Manually tag docker image based on please-release output

# Notes:

## Release-Please output:
```json
{
"releases_created": "true",
"release_created": "true",
"id": "179766252",
"name": "v1.3.1",
"tag_name": "v1.3.1",
"sha": "1785100949bdc314681a91e136a42248406d309f",
"body": "...",
"html_url": "https://github.com/equinor/radix-prometheus-proxy/releases/tag/v1.3.1",
"draft": "false",
"upload_url": "https://uploads.github.com/repos/equinor/radix-prometheus-proxy/releases/179766252/assets{?name,label}",
"path": ".",
"version": "1.3.1",
"major": "1",
"minor": "3",
"patch": "1",
"paths_released": "[\".\"]"
}
```

0 comments on commit 7682e88

Please sign in to comment.