Skip to content

Commit

Permalink
refactor: image release
Browse files Browse the repository at this point in the history
Signed-off-by: Peefy <[email protected]>
  • Loading branch information
Peefy committed Oct 24, 2024
1 parent f60c7cc commit 9dcef53
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 92 deletions.
107 changes: 31 additions & 76 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,20 @@
# https://goreleaser.com/ci/actions/
name: Release
on:
pull_request:
branches:
- main
push:
tags:
- "v*"
branches:
- main
permissions:
contents: write
jobs:
image-amd64:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.11.2
install: true

# <--- Login, build and push image to Docker Hub --->
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: kcllang/kcl
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

image-arm64:
image:
outputs:
hashes: ${{ steps.hash.outputs.hashes }}
image_url: ${{ steps.hash.outputs.image_url }}
image_digest: ${{ steps.hash.outputs.image_digest }}
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -61,51 +29,38 @@ jobs:

- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker login ghcr.io
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
version: v0.11.2
install: true

# <--- Login, build and push image to Docker Hub --->
- name: Login to Docker Hub
uses: docker/login-action@v3
registry: ghcr.io
username: kclbot
password: ${{ secrets.DEPLOY_ACCESS_TOKEN }}
- name: Docker login docker.io
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: kcllang/kcl-arm64
images: |
kcllang/kcl
ghcr.io/kcl-lang/kcl
tags: |
type=raw,value=${{ steps.prep.outputs.version }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
sbom: true
provenance: true
push: true
builder: ${{ steps.buildx.outputs.name }}
context: .
platforms: linux/arm64
push: ${{ github.event_name != 'pull_request' }}
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

binary:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.DEPLOY_ACCESS_TOKEN }}
29 changes: 13 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@ WORKDIR /src
ARG TARGETOS
ARG TARGETARCH

ENV CGO_ENABLED=0
ENV CGO_ENABLED 0

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

FROM --platform=${BUILDPLATFORM} ubuntu:22.04 AS base
ENV LANG=en_US.utf8

FROM base

ARG TARGETARCH
FROM gcr.io/distroless/base-debian11 AS image

COPY --from=build /src/bin/kcl /usr/local/bin/kcl
RUN /usr/local/bin/kcl
RUN apt-get update && apt-get install make gcc git -y && rm -rf /var/lib/apt/lists/*
# Show KCL version
RUN kcl version
# Enable kcl works fine
RUN echo 'a=1' | kcl run -
# Install Git Dependency
RUN apt-get update && apt-get install git -y && rm -rf /var/lib/apt/lists/*
# The reason for doing this below is to prevent the
# container from not having write permissions.
ENV KCL_LIB_HOME=/tmp
ENV KCL_PKG_PATH=/tmp
ENV KCL_CACHE_PATH=/tmp
# Install the tini
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /tini
RUN chmod +x /tini
ENV KCL_LIB_HOME /tmp
ENV KCL_PKG_PATH /tmp
ENV KCL_CACHE_PATH /tmp
ENV LANG en_US.utf8
USER nonroot:nonroot

0 comments on commit 9dcef53

Please sign in to comment.