Docker releases to GitHub Docker registry

This will release docker container to GitHub docker registry.
This commit is contained in:
naveen 2021-02-08 16:33:59 -05:00 committed by Naveen
parent 7ab314db7d
commit 7e158f80e5
2 changed files with 54 additions and 5 deletions

50
.github/workflows/docker.yaml vendored Normal file
View File

@ -0,0 +1,50 @@
name: Docker
on:
push:
branches:
- main
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: scorecard
jobs:
# Push image to GitHub Packages.
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "$default-branch" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION

View File

@ -14,18 +14,17 @@
# syntax = docker/dockerfile:1-experimental
FROM --platform=${BUILDPLATFORM} golang:1.15 as base
FROM golang:1.15 as base
WORKDIR /src
ENV CGO_ENABLED=0
COPY go.* .
COPY go.* ./
RUN go mod download
COPY . .
COPY . ./
FROM base AS build
ARG TARGETOS
ARG TARGETARCH
RUN --mount=type=cache,target=/root/.cache/go-build \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /out/scorecard .
RUN --mount=type=cache,target=/root/.cache/go-build go build -o /out/scorecard .
FROM gcr.io/distroless/base:nonroot
COPY --from=build /out/scorecard /