Skip to content

Commit

Permalink
chore: add build arg for version/hash to devspace and dockerfiles, bu…
Browse files Browse the repository at this point in the history
…mp go/debian versions in dockerfiles, dockerfile consistency stuff (#26)

* chore: add build arg for version/hash to devspace and dockerfiles, bump go/debian versions in dockerfiles, dockerfile consistency stuff

* chore: rename dockerfiles so github is smart enough to highlight things (boo github)

* chore: bump go version in actions, only push images/chart if on main
  • Loading branch information
carlmontanari authored Sep 21, 2023
1 parent 6de7f5d commit d11eaea
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .develop/Dockerfile.dev → .develop/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20
FROM golang:1.21-bookworm

RUN set -x && apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates wget jq procps curl vim inetutils-ping binutils && \
Expand Down
55 changes: 41 additions & 14 deletions .develop/devspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
version: v2beta1
name: clabernetes

Expand All @@ -17,49 +18,58 @@ vars:
LAUNCHER_IMAGE: ${REGISTRY}/${CLABERNETES}-launcher
CLABVERTER_IMAGE: ${REGISTRY}/clabverter

# always build w/ 0.0.0 -- overriden for actual releases by release profile. for "normal" builds
# (not releases) we'll do VERSION-HASH, for releases we'll just override to have version tag.
VERSION: 0.0.0
COMMIT_HASH: $(git describe --always --abbrev=8)

# to be set in ci
RELEASE_VERSION: ""

localRegistry:
enabled: false

images:
clabernetes:
image: ${MANAGER_IMAGE}
clabernetes-dev:
image: ${MANAGER_DEV_IMAGE}
context: ../
dockerfile: ../Dockerfile.manager
dockerfile: dev.Dockerfile
rebuildStrategy: ignoreContextChanges
tags:
- dev-latest
- $(git describe --always --abbrev=8)

clabernetes-dev:
image: ${MANAGER_DEV_IMAGE}
clabernetes:
image: ${MANAGER_IMAGE}
context: ../
dockerfile: Dockerfile.dev
dockerfile: ../build/manager.Dockerfile
rebuildStrategy: ignoreContextChanges
buildArgs:
VERSION: ${VERSION}-${COMMIT_HASH}
tags:
- dev-latest
- $(git describe --always --abbrev=8)

clabernetes-launcher:
image: ${LAUNCHER_IMAGE}
context: ../
dockerfile: ../Dockerfile.launcher
dockerfile: ../build/launcher.Dockerfile
rebuildStrategy: ignoreContextChanges
buildArgs:
VERSION: ${VERSION}-${COMMIT_HASH}
tags:
- dev-latest
- $(git describe --always --abbrev=8)
- ${COMMIT_HASH}

clabverter:
image: ${CLABVERTER_IMAGE}
context: ../
dockerfile: ../clabverter/clabverter.dockerfile
dockerfile: ../build/clabverter.Dockerfile
rebuildStrategy: ignoreContextChanges
buildArgs:
VERSION: "0.0.0-$(git rev-parse --short HEAD)"
VERSION: ${VERSION}-${COMMIT_HASH}
tags:
- dev-latest
- $(git rev-parse --short HEAD)
- ${COMMIT_HASH}

deployments:
clabernetes:
Expand Down Expand Up @@ -137,13 +147,30 @@ profiles:
value:
- latest
- ${RELEASE_VERSION}
- $(git describe --always --abbrev=8)
- ${COMMIT_HASH}
- op: replace
path: images.clabernetes.buildArgs.VERSION
value: ${RELEASE_VERSION}

- op: replace
path: images.clabernetes-launcher.tags
value:
- latest
- ${RELEASE_VERSION}
- $(git describe --always --abbrev=8)
- ${COMMIT_HASH}
- op: replace
path: images.clabernetes-launcher.buildArgs.VERSION
value: ${RELEASE_VERSION}

- op: replace
path: images.clabernetes-clabverter.tags
value:
- latest
- ${RELEASE_VERSION}
- ${COMMIT_HASH}
- op: replace
path: images.clabernetes-clabverter.buildArgs.VERSION
value: ${RELEASE_VERSION}

pipelines:
build:
Expand Down
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
version: 2
updates:
- package-ecosystem: "github-actions"
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch: {}

env:
GO_VERSION: "1.20"
GO_VERSION: "1.21"

jobs:
build:
Expand Down Expand Up @@ -44,9 +44,15 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: build images
- name: <not on main> build images, don't push
if: github.head_ref != 'main'
run: |
devspace run build --skip-push
- name: <on main> build and push images
if: github.head_ref == 'main'
run: |
devspace run build
helm registry login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} ghcr.io
helm package chart --version 0.0.0
helm push clabernetes-0.0.0.tgz oci://ghcr.io/srl-labs/clabernetes
helm push clabernetes-0.0.0.tgz oci://ghcr.io/srl-labs/clabernetes
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch: {}

env:
GO_VERSION: "1.20"
GO_VERSION: "1.21"

jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- created

env:
GO_VERSION: "1.20"
GO_VERSION: "1.21"

jobs:
release:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch: {}

env:
GO_VERSION: "1.20"
GO_VERSION: "1.21"

jobs:
test:
Expand Down
33 changes: 33 additions & 0 deletions build/clabverter.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM golang:1.21-bookworm as builder

ARG VERSION

WORKDIR /clabernetes

RUN mkdir build

COPY cmd/clabverter/main.go main.go

COPY . .

COPY go.mod go.mod
COPY go.sum go.sum

RUN go mod download

RUN CGO_ENABLED=0 \
go build \
-ldflags "-s -w -X github.com/srl-labs/clabernetes/constants.Version=${VERSION}" \
-trimpath \
-a \
-o \
build/clabverter \
main.go

FROM gcr.io/distroless/static-debian12:nonroot

WORKDIR /clabernetes
COPY --from=builder /clabernetes/build/clabverter .
USER nonroot:nonroot

ENTRYPOINT ["/clabernetes/clabverter", "run"]
12 changes: 9 additions & 3 deletions Dockerfile.launcher → build/launcher.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM golang:1.20 as builder
FROM golang:1.21-bookworm as builder

ARG VERSION

WORKDIR /clabernetes

Expand All @@ -17,8 +19,12 @@ RUN CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
go build \
-ldflags="-s -w" \
-a -o build/manager main.go
-ldflags "-s -w -X github.com/srl-labs/clabernetes/constants.Version=${VERSION}" \
-trimpath \
-a \
-o \
build/manager \
main.go

FROM debian:bookworm-slim

Expand Down
16 changes: 11 additions & 5 deletions Dockerfile.manager → build/manager.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM golang:1.20 as builder
FROM golang:1.21-bookworm as builder

ARG VERSION

WORKDIR /clabernetes

Expand All @@ -17,14 +19,18 @@ RUN CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
go build \
-ldflags="-s -w" \
-a -o build/manager main.go
-ldflags "-s -w -X github.com/srl-labs/clabernetes/constants.Version=${VERSION}" \
-trimpath \
-a \
-o \
build/manager \
main.go

FROM gcr.io/distroless/static-debian11:nonroot
FROM gcr.io/distroless/static-debian12:nonroot

WORKDIR /clabernetes
COPY --from=builder --chown=nonroot:nonroot /clabernetes/certificates /clabernetes/certificates
COPY --from=builder /clabernetes/build/manager .
USER nonroot
USER nonroot:nonroot

ENTRYPOINT ["/clabernetes/manager", "run"]
15 changes: 0 additions & 15 deletions clabverter/clabverter.dockerfile

This file was deleted.

0 comments on commit d11eaea

Please sign in to comment.