Skip to content

Commit

Permalink
Merge pull request #5 from holoplot/docker
Browse files Browse the repository at this point in the history
Create container images for kubelish
  • Loading branch information
mhill-holoplot authored Feb 3, 2025
2 parents 87addc7 + 1053f6a commit 23b9f10
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -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


20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 23b9f10

Please sign in to comment.