Skip to content

Commit

Permalink
Merge pull request #41 from lazyfrosch/feature/containers
Browse files Browse the repository at this point in the history
Add container image build
  • Loading branch information
loafoe authored Jan 4, 2023
2 parents b7e1de2 + 987d7a6 commit f234f4c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish container images

on:
push:
branches:
- main
tags:
- 'v*'
pull_request:

jobs:
containers:
name: Build and push container image registries
runs-on: ubuntu-latest

permissions:
packages: write
contents: read

steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(github.ref, 'refs/tags/v') || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}

- name: Build and push Docker images
uses: docker/build-push-action@v3
with:
push: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
13 changes: 4 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
FROM golang:1.19.4 as builder
WORKDIR /build
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . /build/

# Build
COPY . .
RUN git rev-parse --short HEAD
RUN GIT_COMMIT=$(git rev-parse --short HEAD) && \
CGO_ENABLED=0 go build -o app -ldflags "-X main.GitCommit=${GIT_COMMIT}"
RUN go mod download
RUN CGO_ENABLED=0 go build -o app

FROM alpine:latest
FROM alpine:latest
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
WORKDIR /app
COPY --from=builder /build/app /app
Expand Down

0 comments on commit f234f4c

Please sign in to comment.