Skip to content

Commit

Permalink
ci: update goreleaser config to build docker images
Browse files Browse the repository at this point in the history
This might be broken - fixing CI stuff is annoying.
  • Loading branch information
d-Rickyy-b committed Dec 14, 2023
1 parent fd01dda commit 109e8d6
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 60 deletions.
54 changes: 52 additions & 2 deletions .github/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ before:

builds:
- main: ./cmd/main.go
ldflags: -s -w
ldflags: -s -w -X github.com/d-Rickyy-b/certstream-server-go/internal/config.Version={{.Version}}
env:
- CGO_ENABLED=0
goos:
Expand All @@ -30,10 +30,60 @@ builds:
- goos: windows
goarch: 386
checksum:
name_template: '{{ .ProjectName }}_{{.Version}}_checksums.txt'
name_template: '{{.ProjectName}}_{{.Version}}_checksums.txt'
changelog:
skip: true

dockers:
- image_templates:
- '0rickyy0/{{.ProjectName}}:{{.Tag}}-amd64'
- '0rickyy0/{{.ProjectName}}:{{.Tag}}'
- 'ghcr.io/0rickyy0/{{.ProjectName}}:{{.Tag}}-amd64'
- 'ghcr.io/0rickyy0/{{.ProjectName}}:latest-amd64'
goarch: amd64
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.description=Certstream server written in Go"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.source=https://github.com/0Rickyy0/certstream-server-go"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--platform=linux/amd64"

- image_templates:
- '0rickyy0/{{.ProjectName}}:{{.Tag}}-arm64'
- '0rickyy0/{{.ProjectName}}:latest-arm64'
- 'ghcr.io/0rickyy0/{{.ProjectName}}:{{.Tag}}-arm64'
- 'ghcr.io/0rickyy0/{{.ProjectName}}:latest-arm64'
goarch: arm64
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.description=Certstream server written in Go"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.source=https://github.com/0Rickyy0/certstream-server-go"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--platform=linux/arm64"

docker_manifests:
- name_template: '0rickyy0/{{.ProjectName}}:{{.Tag}}'
image_templates:
- '0rickyy0/{{.ProjectName}}:{{.Tag}}-amd64'
- '0rickyy0/{{.ProjectName}}:{{.Tag}}-arm64'
- 'ghcr.io/0rickyy0/{{.ProjectName}}:{{.Tag}}-amd64'
- 'ghcr.io/0rickyy0/{{.ProjectName}}:{{.Tag}}-arm64'

- name_template: '{{ if not .Prerelease }}0rickyy0/{{.ProjectName}}:latest{{ end }}'
image_templates:
- '0rickyy0/{{.ProjectName}}:{{.Tag}}-amd64'
- '0rickyy0/{{.ProjectName}}:{{.Tag}}-arm64'
- 'ghcr.io/0rickyy0/{{.ProjectName}}:{{.Tag}}-amd64'
- 'ghcr.io/0rickyy0/{{.ProjectName}}:{{.Tag}}-arm64'

archives:
- format: binary
name_template: >-
Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/docker_build.yml

This file was deleted.

16 changes: 14 additions & 2 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,29 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Set up Go 1.18
- name: Set up Go 1.21
uses: actions/setup-go@v3
with:
go-version: ^1.18
go-version: ^1.21
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/

- name: Setup QEMU # Used for cross-compiling with goreleaser / docker
uses: docker/setup-qemu-action@v3

- name: Setup Docker Buildx # Used for cross-compiling with goreleaser / docker
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: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
Expand Down
35 changes: 5 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Thanks to https://chemidy.medium.com/create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324
############################
# STEP 1 build executable binary
############################
FROM golang:alpine AS builder
FROM alpine

WORKDIR /app

ENV USER=certstreamserver
ENV UID=10001
Expand All @@ -17,36 +15,13 @@ RUN adduser \
--uid "${UID}" \
"${USER}"

# Install git. Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git
WORKDIR $GOPATH/src/certstream-server-go/
COPY . .

# Fetch dependencies.
RUN go mod download

# Build the binary.
RUN go build -ldflags="-w -s" -o /go/bin/certstream-server-go $GOPATH/src/certstream-server-go/cmd
RUN chown -R "${USER}:${USER}" /go/bin/certstream-server-go

############################
# STEP 2 build a small image
############################
FROM alpine

WORKDIR /app

# Import the user and group files from the builder.
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group

# Copy our static executable.
COPY --from=builder /go/bin/certstream-server-go /app/certstream-server-go
COPY certstream-server-go /app/certstream-server-go
COPY ./config.sample.yaml /app/config.yaml

# Use an unprivileged user.
USER certstreamserver:certstreamserver

EXPOSE 8080

ENTRYPOINT ["/app/certstream-server-go"]
ENTRYPOINT ["/app/certstream-server-go"]
52 changes: 52 additions & 0 deletions Dockerfile_multistage
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Thanks to https://chemidy.medium.com/create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324
############################
# STEP 1 build executable binary
############################
FROM golang:alpine AS builder

ENV USER=certstreamserver
ENV UID=10001

# Create user
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"

# Install git. Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git
WORKDIR $GOPATH/src/certstream-server-go/
COPY . .

# Fetch dependencies.
RUN go mod download

# Build the binary.
RUN go build -ldflags="-w -s" -o /go/bin/certstream-server-go $GOPATH/src/certstream-server-go/cmd
RUN chown -R "${USER}:${USER}" /go/bin/certstream-server-go

############################
# STEP 2 build a small image
############################
FROM alpine

WORKDIR /app

# Import the user and group files from the builder.
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group

# Copy our static executable.
COPY --from=builder /go/bin/certstream-server-go /app/certstream-server-go
COPY ./config.sample.yaml /app/config.yaml

# Use an unprivileged user.
USER certstreamserver:certstreamserver

EXPOSE 8080

ENTRYPOINT ["/app/certstream-server-go"]

0 comments on commit 109e8d6

Please sign in to comment.