Skip to content

Commit

Permalink
feat: publish api-server to ghcr.io (traefik-workshops#37)
Browse files Browse the repository at this point in the history
* feat: publish api-server to ghcr.io

* fix
  • Loading branch information
darkweaver87 authored and immanuelfodor committed Feb 26, 2024
1 parent 155f7cc commit c9e4d34
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/api-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: 🚀 Build/Release docker api-server
on:
workflow_dispatch:
pull_request:
branches:
- master
paths:
- '.github/workflow/api-server.yaml'
- 'api-server/**'
push:
branches:
- master
paths:
- '.github/workflow/api-server.yaml'
- 'api-server/**'
tags:
- 'api-server_v[0-9]+.[0-9]+.[0-9]+'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: docker login
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: set up buildx
uses: docker/setup-buildx-action@v3
- name: docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ github.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=match,pattern=api-server_v\d+.\d+.\d+
type=raw,value={{branch}}-{{sha}}-{{date 'X'}},enable={{is_default_branch}}
type=ref,event=pr
- name: build docker images
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:api-server"
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
15 changes: 11 additions & 4 deletions api-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# syntax=docker/dockerfile:1.2
# Alpine
# syntax=docker/dockerfile:1.6

# golang builder
FROM golang:1.21 as builder
WORKDIR /usr/local/src/
COPY . /usr/local/src/
RUN make build

# docker image
FROM alpine

RUN apk --no-cache --no-progress add ca-certificates tzdata git \
RUN apk --no-cache --no-progress add ca-certificates tzdata \
&& rm -rf /var/cache/apk/*

ARG TARGETPLATFORM
COPY ./dist/$TARGETPLATFORM/api-server /
COPY --from=builder /usr/local/src/dist/$TARGETPLATFORM/api-server /

ENTRYPOINT ["/api-server"]
EXPOSE 3000

0 comments on commit c9e4d34

Please sign in to comment.