From cd41e21da4dbfbdd21be30ef347f793ffc777643 Mon Sep 17 00:00:00 2001 From: Morgan Hill Date: Mon, 3 Feb 2025 15:09:15 +0100 Subject: [PATCH 1/2] Create a basic docker image --- Dockerfile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1275860 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS build +ARG TARGETOS +ARG TARGETARCH + +WORKDIR /go/src/github.com/holoplot/kubelish + +# Only invalidate the download layer if the modules changed +COPY ["go.mod", "go.sum", "./"] +RUN go mod download + +COPY . . +RUN --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build ./cmd/kubelish/main.go + +FROM alpine:3.21 + +RUN apk add --update ca-certificates && rm -rf /var/cache/apk/* +COPY --from=build /go/src/github.com/holoplot/kubelish/main kubelish + +ENTRYPOINT ["/kubelish"] From 1053f6af8134460c9cd5bb77b776021ecc0d426f Mon Sep 17 00:00:00 2001 From: Morgan Hill Date: Mon, 3 Feb 2025 15:11:27 +0100 Subject: [PATCH 2/2] Add an action for building and pushing OCI image --- .github/workflows/go.yml | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..fbcdba2 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,67 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + release: + types: + - published + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.23 + + - name: Unit Test + run: go test -v ./... + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + # list of Docker images to use as base name for tags + images: | + ${{ secrets.DOCKERHUB_USERNAME }}/kubelish + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + - name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build + uses: docker/build-push-action@v6 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + +