Skip to content

Commit af86f65

Browse files
committed
Build and publish container image
1 parent 963825d commit af86f65

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

.github/workflows/docker.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Build and Push Container Image
2+
on: [push]
3+
env:
4+
IMAGE_NAME: ghcr.io/4armed/metacreds
5+
6+
jobs:
7+
build-and-push:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v2
12+
- name: Login to GitHub Container Registry
13+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
14+
- name: Get version
15+
id: vars
16+
run: echo ::set-output name=tag::$(echo ${GITHUB_SHA} | cut -c1-7)
17+
- name: Build the tagged Docker image
18+
run: docker build . -f build/Dockerfile --tag ${{ env.IMAGE_NAME }}:${{steps.vars.outputs.tag}} --build-arg EXECUTABLE=metacreds
19+
- name: Push the tagged Docker image
20+
run: docker push ${{ env.IMAGE_NAME }}:${{steps.vars.outputs.tag}}
21+
- name: Tag image as latest
22+
run: docker tag ${{ env.IMAGE_NAME }}:${{steps.vars.outputs.tag}} ${{ env.IMAGE_NAME }}:latest
23+
- name: Push latest
24+
run: docker push ${{ env.IMAGE_NAME }}:latest

Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
EXECUTABLE := $(EXECUTABLE)
2+
3+
clean:
4+
@rm -f ${EXECUTABLE}
5+
6+
install: clean
7+
go install -a -tags netgo -ldflags "-w -extldflags '-static'"
8+
9+
docker:
10+
docker build -f build/Dockerfile . -t ${EXECUTABLE} --build-arg EXECUTABLE=$(EXECUTABLE)

build/Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM golang:1.17-alpine AS build
2+
3+
ENV CGO_ENABLED=0
4+
5+
RUN apk add --no-cache \
6+
git \
7+
curl \
8+
make
9+
10+
WORKDIR /src
11+
COPY . .
12+
RUN make install
13+
14+
FROM gcr.io/distroless/base
15+
16+
ARG EXECUTABLE
17+
ENV EXECUTABLE=$EXECUTABLE
18+
19+
COPY --from=build /go/bin/${EXECUTABLE} /metacreds
20+
ENTRYPOINT ["/metacreds"]

0 commit comments

Comments
 (0)