add github action to push image (#21)

Co-authored-by: sh0rez <me@shorez.de>
This commit is contained in:
Jeroen Op 't Eynde 2021-06-04 22:10:06 +02:00 committed by GitHub
parent 5776ff829f
commit 4f0571d7e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 4 deletions

56
.github/workflows/docker.yml vendored Normal file
View file

@ -0,0 +1,56 @@
# https://github.com/marketplace/actions/build-and-push-docker-images#git-context
name: ci
on:
push:
branches:
- 'master'
tags:
- 'v*'
pull_request:
branches:
- 'master'
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: jsonnetlibs/docsonnet
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

View file

@ -1,4 +1,4 @@
FROM golang:1.16.4 as base FROM --platform=$BUILDPLATFORM golang:1.16.4 as base
ENV GO111MODULE=on ENV GO111MODULE=on
WORKDIR /app WORKDIR /app
@ -11,7 +11,9 @@ RUN go mod download
COPY . . COPY . .
FROM base AS builder FROM base AS builder
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags='-s -w -extldflags "-static"' .
ENV GOARCH=$TARGETARCH
RUN CGO_ENABLED=0 go build -ldflags='-s -w -extldflags "-static"' .
FROM alpine:3.12 FROM alpine:3.12
COPY --from=builder /app/docsonnet /usr/local/bin COPY --from=builder /app/docsonnet /usr/local/bin

View file

@ -1,11 +1,11 @@
.PHONY: build test push push-image .PHONY: build test push push-image
IMAGE_NAME ?= docsonnet IMAGE_NAME ?= docsonnet
IMAGE_PREFIX ?= jsonnet-libs IMAGE_PREFIX ?= jsonnetlibs
IMAGE_TAG ?= 0.0.1 IMAGE_TAG ?= 0.0.1
build: build:
docker build -t $(IMAGE_PREFIX)/$(IMAGE_NAME):$(IMAGE_TAG) . docker buildx build -t $(IMAGE_PREFIX)/$(IMAGE_NAME):$(IMAGE_TAG) .
test: build test: build