Skip to content

Commit

Permalink
ci: add docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDark committed Oct 31, 2024
1 parent 938d084 commit d803c18
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Docker Builds

on:
workflow_dispatch:
push:
branches:
- "main"
tags:
- "v*.*.*"

permissions:
contents: read
packages: write

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
runs-on: ubuntu-latest
steps:
# Get the repositery's code
- name: Checkout
uses: actions/checkout@v4

- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
with:
short-length: 8 # Same as v3 and before

# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:qemu-v8.1.5 # more recent

# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

# - name: Available platforms
# run: echo ${{ steps.buildx.outputs.platforms }}

- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# - name: Login to Docker Hub
# if: github.event_name != 'pull_request'
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta for PMS
id: meta_pms
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/${{ github.repository }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push PMS
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64 # works only on x86 systems and intel
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta_pms.outputs.tags }}
labels: ${{ steps.meta_pms.outputs.labels }}
build-args: |
BUILD_VERSION=${{ env.GITHUB_REF_SLUG }}
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

FROM golang:1.23 AS BUILD

Check warning on line 3 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

Stage names should be lowercase

StageNameCasing: Stage name 'BUILD' should be lowercase More info: https://docs.docker.com/go/dockerfile/rule/stage-name-casing/
WORKDIR /app
ARG BUILD_VERSION=dev

# Download Go modules
COPY go.mod go.sum ./
Expand All @@ -12,9 +13,9 @@ RUN go mod download
COPY *.go ./

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -o /turbostat-exporter
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'main.Version=${BUILD_VERSION}'" -o /turbostat-exporter

FROM debian:12.7-slim
FROM debian:sid-slim

RUN <<EOF
apt update
Expand All @@ -23,3 +24,4 @@ RUN <<EOF
EOF

COPY --from=BUILD /turbostat-exporter /usr/bin/turbostat-exporter

0 comments on commit d803c18

Please sign in to comment.