Skip to content

Commit 3e831e5

Browse files
committed
Simplify Dockerfile and chain docker publish after release
1 parent d028244 commit 3e831e5

3 files changed

Lines changed: 71 additions & 81 deletions

File tree

.github/workflows/docker-release.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
permissions:
1010
contents: write
11+
packages: write
1112

1213
jobs:
1314
build:
@@ -90,3 +91,63 @@ jobs:
9091
dist/sops-cop_*
9192
dist/checksums.txt
9293
generate_release_notes: true
94+
95+
docker:
96+
name: Build and push container images
97+
runs-on: ubuntu-latest
98+
needs: release
99+
if: startsWith(github.ref, 'refs/tags/v')
100+
permissions:
101+
contents: read
102+
packages: write
103+
env:
104+
VERSION: ${{ github.ref_name }}
105+
106+
steps:
107+
- name: Checkout
108+
uses: actions/checkout@v6
109+
110+
- name: Set up QEMU
111+
uses: docker/setup-qemu-action@v3
112+
113+
- name: Set up Docker Buildx
114+
uses: docker/setup-buildx-action@v3
115+
116+
- name: Log in to GHCR
117+
uses: docker/login-action@v3
118+
with:
119+
registry: ghcr.io
120+
username: ${{ github.actor }}
121+
password: ${{ secrets.GITHUB_TOKEN }}
122+
123+
- name: Log in to Docker Hub
124+
uses: docker/login-action@v3
125+
with:
126+
registry: docker.io
127+
username: ${{ secrets.DOCKER_USERNAME }}
128+
password: ${{ secrets.DOCKER_PASSWORD }}
129+
scope: binbashing/sops-cop@push
130+
131+
- name: Extract Docker metadata
132+
id: meta
133+
uses: docker/metadata-action@v5
134+
with:
135+
images: |
136+
ghcr.io/${{ github.repository }}
137+
docker.io/binbashing/sops-cop
138+
tags: |
139+
type=raw,value=${{ env.VERSION }}
140+
type=sha
141+
type=raw,value=latest,enable=${{ startsWith(env.VERSION, 'v') }}
142+
143+
- name: Build and push image
144+
uses: docker/build-push-action@v6
145+
with:
146+
context: .
147+
file: ./Dockerfile
148+
platforms: linux/amd64,linux/arm64
149+
push: true
150+
tags: ${{ steps.meta.outputs.tags }}
151+
labels: ${{ steps.meta.outputs.labels }}
152+
build-args: |
153+
VERSION=${{ env.VERSION }}

Dockerfile

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1-
FROM --platform=$BUILDPLATFORM golang:1-alpine AS builder
2-
3-
WORKDIR /src
4-
5-
COPY go.mod go.sum ./
6-
RUN go mod download
1+
FROM alpine:3
72

8-
COPY . .
3+
WORKDIR /app
94

105
ARG VERSION=dev
116
ARG TARGETOS
127
ARG TARGETARCH
13-
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
14-
-trimpath \
15-
-ldflags="-s -w -X main.version=${VERSION}" \
16-
-o /out/sops-cop .
17-
18-
FROM alpine:3
8+
RUN apk add --no-cache ca-certificates curl && \
9+
case "${TARGETARCH}" in amd64|arm64) ;; *) echo "unsupported arch: ${TARGETARCH}"; exit 1 ;; esac && \
10+
BINARY_NAME="sops-cop_${VERSION}_${TARGETOS}_${TARGETARCH}" && \
11+
URL="https://github.com/binbashing/sops-cop/releases/download/${VERSION}/${BINARY_NAME}" && \
12+
curl --fail --silent --show-error --location \
13+
--retry 8 --retry-delay 5 --retry-connrefused \
14+
"${URL}" --output /usr/local/bin/sops-cop && \
15+
chmod +x /usr/local/bin/sops-cop
1916

2017
RUN addgroup -S app && adduser -S app -G app
2118

22-
WORKDIR /app
23-
COPY --from=builder /out/sops-cop /usr/local/bin/sops-cop
24-
2519
USER app
2620
ENTRYPOINT ["/usr/local/bin/sops-cop"]
2721
CMD ["-target", "."]

0 commit comments

Comments
 (0)