Skip to content

Commit

Permalink
Fix execuable versioning inside docker container (#96)
Browse files Browse the repository at this point in the history
* bug: fix docker git versioning

* feat: include docker cache mount

* ci: Split docker to seperate workflow
  • Loading branch information
Cyb3r-Jak3 authored Aug 6, 2024
1 parent f11e795 commit 30763a0
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 57 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Docker
on:
push:
branches:
- '**'
tags:
- 'v*'
paths:
- 'go.sum'
- 'go.mod'
- '**.go'
- .github/workflows/docker.yml
- dist.Dockerfile
pull_request:
branches:
- main
paths:
- '**.go'
- 'go.sum'
- 'go.mod'
- dist.Dockerfile
- .github/workflows/docker.yml

permissions:
actions: write
packages: write
id-token: write
attestations: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Docker:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Login to DockerHub
uses: docker/login-action@v3
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
with:
username: cyb3rjak3
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to GitHub Container Registry
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: cyb3rjak3/cloudflare-utils,ghcr.io/cyb3r-jak3/cloudflare-utils

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

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

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
path: cloudflare-utils

- name: Build
uses: docker/build-push-action@v6
id: build
with:
context: cloudflare-utils
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6, linux/386
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: cloudflare-utils/dist.Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
sbom: true
provenance: mode=max

- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
with:
username: cyb3rjak3
password: ${{ secrets.DOCKER_PASSWORD }}
repository: cyb3rjak3/cloudflare-utils
readme-filepath: cloudflare-utils/README.md

- name: GitHub Container Attestation
uses: actions/attest-build-provenance@v1
id: attest
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
with:
subject-name: ghcr.io/cyb3r-jak3/cloudflare-utils
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true
56 changes: 0 additions & 56 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true


jobs:
Snapshot:
if: ${{ startsWith(github.ref, 'refs/tags/v') == false }}
Expand Down Expand Up @@ -81,61 +80,6 @@ jobs:
name: cloudflare-utils
path: cmd/cloudflare-utils/dist/*

Docker:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Login to DockerHub
uses: docker/login-action@v3
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
with:
username: cyb3rjak3
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to GitHub Container Registry
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: cyb3rjak3/cloudflare-utils,ghcr.io/cyb3r-jak3/cloudflare-utils

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

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

- name: Checkout code
uses: actions/checkout@v4

- name: Build
uses: docker/build-push-action@v6
with:
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6, linux/386
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: dist.Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
sbom: true

- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
with:
username: cyb3rjak3
password: ${{ secrets.DOCKER_PASSWORD }}
repository: cyb3rjak3/cloudflare-utils

Release:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: windows-latest
Expand Down
4 changes: 3 additions & 1 deletion dist.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ WORKDIR /usr/app
ENV CGO_ENABLED=0
RUN apk update && apk -U --no-cache add git make build-base ca-certificates && git config --global --add safe.directory '*'
COPY . .
RUN make build
RUN go mod download
ENV GOCACHE=/root/.cache/go-build
RUN --mount=type=cache,target="/root/.cache/go-build" make build

FROM scratch
COPY --from=builder /usr/app/cloudflare-utils /
Expand Down

0 comments on commit 30763a0

Please sign in to comment.