Skip to content

Commit

Permalink
docker-push-scratch-image-docker
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver006 committed Oct 14, 2024
1 parent b879136 commit 3fc8fd6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,36 @@ jobs:
artifacts: "dist/*"
allowUpdates: true
omitBodyDuringUpdate: true


docker-push-scratch-image-docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push scratch image
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm,linux/arm64
push: true
tags: "latest,${{ github.ref_name }},"
target: scratch-release
context: .
file: ./docker/Dockerfile
build_args: "TAG=${{ github.ref_name }},SHA1=${{ github.sha }}"
16 changes: 9 additions & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
ARG GOARCH
ARG TARGETPLATFORM

#
# build container
#
FROM --platform=linux/amd64 golang:1.23-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder
WORKDIR /go/src/github.com/oliver006/redis_exporter/

ADD . /go/src/github.com/oliver006/redis_exporter/

ARG SHA1="[no-sha]"
ARG TAG="[no-tag]"
ARG GOARCH
ARG TARGETOS
ARG TARGETARCH

#RUN printf "nameserver 1.1.1.1\nnameserver 8.8.8.8"> /etc/resolv.conf \ && apk --no-cache add ca-certificates git

RUN apk --no-cache add ca-certificates git
RUN BUILD_DATE=$(date +%F-%T) CGO_ENABLED=0 GOOS=linux GOARCH=$GOARCH go build -o /redis_exporter \
RUN BUILD_DATE=$(date +%F-%T) CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /redis_exporter \
-ldflags "-s -w -extldflags \"-static\" -X main.BuildVersion=$TAG -X main.BuildCommitSha=$SHA1 -X main.BuildDate=$BUILD_DATE" .

RUN [ "$GOARCH" = "amd64" ] && /redis_exporter -version || ls -la /redis_exporter
RUN [ "$TARGETARCH" = "amd64" ] && /redis_exporter -version || ls -la /redis_exporter

#
# scratch release container
#
FROM --platform=linux/$GOARCH scratch AS scratch-release
FROM --platform=$TARGETPLATFORM scratch AS scratch-release

COPY --from=builder /redis_exporter /redis_exporter
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
Expand All @@ -38,7 +40,7 @@ ENTRYPOINT [ "/redis_exporter" ]
#
# Alpine release container
#
FROM --platform=linux/$GOARCH alpine:3.20 AS alpine
FROM --platform=$TARGETPLATFORM alpine:3.20 AS alpine

COPY --from=builder /redis_exporter /redis_exporter
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
Expand Down

0 comments on commit 3fc8fd6

Please sign in to comment.