Skip to content

Commit

Permalink
ci: include version and commit in docker images (#136)
Browse files Browse the repository at this point in the history
* ci: include version and commit in docker images

* ci: add checkout again

* ci: generate client bundles for docker
  • Loading branch information
ayuhito authored Sep 3, 2024
1 parent f42dcc0 commit 5390883
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/docker-edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ jobs:
id-token: write

steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Save GitHub tag and commit sha to environment
run: |
echo "VERSION=Edge" >> $GITHUB_ENV
echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
Expand All @@ -53,6 +59,9 @@ jobs:
with:
context: .
push: true
build-args: |
VERSION=${{ env.VERSION }}
COMMIT_SHA=${{ env.COMMIT_SHA }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/docker-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ jobs:
id-token: write

steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Save GitHub tag and commit sha to environment
run: |
echo "VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
Expand All @@ -49,6 +55,9 @@ jobs:
with:
context: .
push: true
build-args: |
VERSION=${{ env.VERSION }}
COMMIT_SHA=${{ env.COMMIT_SHA }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
Expand Down
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

FROM jdxcode/mise:latest AS build

ARG VERSION=development
ARG COMMIT_SHA=development

ENV VERSION=${VERSION}
ENV COMMIT_SHA=${COMMIT_SHA}

WORKDIR /app

# Install unzip dependency for bun
Expand All @@ -28,9 +34,12 @@ RUN --mount=type=cache,target=${GOCACHE} \

RUN bun install --frozen-lockfile

# Verify environment variables
RUN echo "VERSION=${VERSION}" && echo "COMMIT_SHA=${COMMIT_SHA}"

# Copy the rest of the source code
COPY . .
RUN --mount=type=cache,target=${GOCACHE} ~/bin/task core:release
RUN --mount=type=cache,target=${GOCACHE} ~/bin/task core:release:docker

# Build the final image
FROM gcr.io/distroless/cc-debian12
Expand Down
15 changes: 15 additions & 0 deletions core/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,19 @@ tasks:
env:
CGO_ENABLED: "1"

# Centralise Docker release command into here for simpler maintenance instead of specifying
# within Dockerfile
release:docker:
deps: [generate]
cmds:
- go build -o ./bin/main -ldflags "-s -w -X main.Version=$VERSION -X main.Commit=$COMMIT_SHA" -trimpath -tags "no_duckdb_arrow" ./cmd/
- chmod +x ./bin/main
- echo "docker build done"
env:
CGO_ENABLED: "1"

release:linux:amd64:
deps: [generate]
cmds:
- go build -o ./bin/medama_linux_amd64 -ldflags "-s -w -X main.Version=$VERSION -X main.Commit=$COMMIT_SHA" -trimpath -tags "no_duckdb_arrow" ./cmd/
- chmod +x ./bin/medama_linux_amd64
Expand All @@ -99,6 +111,7 @@ tasks:
GOARCH: "amd64"

release:linux:arm64:
deps: [generate]
cmds:
- go build -o ./bin/medama_linux_arm64 -ldflags "-s -w -X main.Version=$VERSION -X main.Commit=$COMMIT_SHA" -trimpath -tags "no_duckdb_arrow" ./cmd/
- chmod +x ./bin/medama_linux_arm64
Expand All @@ -111,6 +124,7 @@ tasks:
GOARCH: "arm64"

release:darwin:amd64:
deps: [generate]
cmds:
- go build -o ./bin/medama_darwin_amd64 -ldflags "-s -w -X main.Version=$VERSION -X main.Commit=$COMMIT_SHA" -trimpath -tags "no_duckdb_arrow" ./cmd/
- chmod +x ./bin/medama_darwin_amd64
Expand All @@ -121,6 +135,7 @@ tasks:
GOARCH: "amd64"

release:darwin:arm64:
deps: [generate]
cmds:
- go build -o ./bin/medama_darwin_arm64 -ldflags "-s -w -X main.Version=$VERSION -X main.Commit=$COMMIT_SHA" -trimpath -tags "no_duckdb_arrow" ./cmd/
- chmod +x ./bin/medama_darwin_arm64
Expand Down

0 comments on commit 5390883

Please sign in to comment.