Skip to content

Commit 767fa8d

Browse files
authored
Merge pull request #154 from Peefy/refactor-image-release
refactor: smaller size and multi arch image release
2 parents f60c7cc + a6b3bda commit 767fa8d

File tree

2 files changed

+46
-70
lines changed

2 files changed

+46
-70
lines changed

.github/workflows/release.yaml

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,11 @@ on:
88
permissions:
99
contents: write
1010
jobs:
11-
image-amd64:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- name: Checkout
15-
uses: actions/checkout@v4
16-
with:
17-
fetch-depth: 0
18-
- name: Set up Go
19-
uses: actions/setup-go@v5
20-
with:
21-
go-version-file: go.mod
22-
23-
- name: Setup Docker Buildx
24-
uses: docker/setup-buildx-action@v3
25-
with:
26-
version: v0.11.2
27-
install: true
28-
29-
# <--- Login, build and push image to Docker Hub --->
30-
- name: Login to Docker Hub
31-
uses: docker/login-action@v3
32-
with:
33-
username: ${{ secrets.DOCKER_USERNAME }}
34-
password: ${{ secrets.DOCKER_PASSWORD }}
35-
36-
- name: Extract metadata (tags, labels) for Docker
37-
id: meta
38-
uses: docker/metadata-action@v5
39-
with:
40-
images: kcllang/kcl
41-
- name: Build and push Docker image
42-
uses: docker/build-push-action@v6
43-
with:
44-
context: .
45-
platforms: linux/amd64
46-
push: ${{ github.event_name != 'pull_request' }}
47-
tags: ${{ steps.meta.outputs.tags }}
48-
labels: ${{ steps.meta.outputs.labels }}
49-
50-
image-arm64:
11+
image:
12+
outputs:
13+
hashes: ${{ steps.hash.outputs.hashes }}
14+
image_url: ${{ steps.hash.outputs.image_url }}
15+
image_digest: ${{ steps.hash.outputs.image_digest }}
5116
runs-on: ubuntu-latest
5217
steps:
5318
- name: Checkout
@@ -61,32 +26,40 @@ jobs:
6126

6227
- name: Setup QEMU
6328
uses: docker/setup-qemu-action@v3
64-
with:
65-
platforms: all
6629
- name: Setup Docker Buildx
30+
id: buildx
6731
uses: docker/setup-buildx-action@v3
32+
- name: Docker login ghcr.io
33+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
6834
with:
69-
version: v0.11.2
70-
install: true
71-
72-
# <--- Login, build and push image to Docker Hub --->
73-
- name: Login to Docker Hub
74-
uses: docker/login-action@v3
35+
registry: ghcr.io
36+
username: kclbot
37+
password: ${{ secrets.DEPLOY_ACCESS_TOKEN }}
38+
- name: Docker login docker.io
39+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
7540
with:
7641
username: ${{ secrets.DOCKER_USERNAME }}
7742
password: ${{ secrets.DOCKER_PASSWORD }}
78-
79-
- name: Extract metadata (tags, labels) for Docker
43+
- name: Docker meta
8044
id: meta
81-
uses: docker/metadata-action@v5
45+
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
8246
with:
83-
images: kcllang/kcl-arm64
47+
images: |
48+
kcllang/kcl
49+
ghcr.io/kcl-lang/kcl
50+
tags: |
51+
type=raw,value=v0.10.6
52+
8453
- name: Build and push Docker image
8554
uses: docker/build-push-action@v6
8655
with:
56+
sbom: true
57+
provenance: true
58+
push: true
59+
builder: ${{ steps.buildx.outputs.name }}
8760
context: .
88-
platforms: linux/arm64
89-
push: ${{ github.event_name != 'pull_request' }}
61+
file: ./Dockerfile
62+
platforms: linux/amd64,linux/arm64
9063
tags: ${{ steps.meta.outputs.tags }}
9164
labels: ${{ steps.meta.outputs.labels }}
9265

Dockerfile

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,25 @@ ENV CGO_ENABLED=0
1313

1414
RUN --mount=type=cache,target=/go/pkg --mount=type=cache,target=/root/.cache/go-build GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build
1515

16-
FROM --platform=${BUILDPLATFORM} ubuntu:22.04 AS base
17-
ENV LANG=en_US.utf8
16+
FROM debian:11-slim AS image
1817

19-
FROM base
18+
COPY --from=build /src/bin/kcl /usr/local/bin/kcl
19+
# Verify KCL installation and basic functionality
20+
RUN kcl version && \
21+
echo 'a=1' | kcl run -
2022

21-
ARG TARGETARCH
23+
# Install git for KCL package management
24+
# Use best practices for apt-get commands
25+
RUN apt-get update && \
26+
apt-get install -y --no-install-recommends git && \
27+
rm -rf /var/lib/apt/lists/*
2228

23-
COPY --from=build /src/bin/kcl /usr/local/bin/kcl
24-
RUN /usr/local/bin/kcl
25-
RUN apt-get update && apt-get install make gcc git -y && rm -rf /var/lib/apt/lists/*
26-
# The reason for doing this below is to prevent the
27-
# container from not having write permissions.
28-
ENV KCL_LIB_HOME=/tmp
29-
ENV KCL_PKG_PATH=/tmp
30-
ENV KCL_CACHE_PATH=/tmp
31-
# Install the tini
32-
ENV TINI_VERSION v0.19.0
33-
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /tini
34-
RUN chmod +x /tini
29+
# Configure KCL runtime environment
30+
# Set temporary directories for write permissions
31+
ENV KCL_LIB_HOME=/tmp \
32+
KCL_PKG_PATH=/tmp \
33+
KCL_CACHE_PATH=/tmp \
34+
LANG=en_US.utf8
35+
36+
# Switch to non-root user for security
37+
USER nonroot:nonroot

0 commit comments

Comments
 (0)