Skip to content

Commit

Permalink
add github action to push image (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: sh0rez <[email protected]>
  • Loading branch information
Duologic and sh0rez authored Jun 4, 2021
1 parent 5776ff8 commit 4f0571d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.16.4 as base
FROM --platform=$BUILDPLATFORM golang:1.16.4 as base

ENV GO111MODULE=on
WORKDIR /app
Expand All @@ -11,7 +11,9 @@ RUN go mod download
COPY . .

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
COPY --from=builder /app/docsonnet /usr/local/bin
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.PHONY: build test push push-image

IMAGE_NAME ?= docsonnet
IMAGE_PREFIX ?= jsonnet-libs
IMAGE_PREFIX ?= jsonnetlibs
IMAGE_TAG ?= 0.0.1

build:
docker build -t $(IMAGE_PREFIX)/$(IMAGE_NAME):$(IMAGE_TAG) .
docker buildx build -t $(IMAGE_PREFIX)/$(IMAGE_NAME):$(IMAGE_TAG) .

test: build

Expand Down

0 comments on commit 4f0571d

Please sign in to comment.