Skip to content

Commit

Permalink
Added ghcr registry push
Browse files Browse the repository at this point in the history
  • Loading branch information
chefgs committed Aug 29, 2023
1 parent a4eac7e commit 69fab9f
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/linktoqr_ci_gh_registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Link-to-QR CI

on:
push:
branches: [ "**" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:

go_ci_job:
name: Go CI Job
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Go CI code Lint
uses: golangci/golangci-lint-action@v3

- name: Go CI code Unit Test
run: go test -v ./...

- name: Run Go Build
run: go build -v ./...

- name: Setup docker
uses: docker/setup-buildx-action@v2.7.0

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4.6.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Docker Build and Push
id: build-and-push
uses: docker/build-push-action@v4.1.1
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}, ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM golang:alpine

LABEL org.opencontainers.image.source=https://github.com/chefgs/linktoqr

# Set necessary environmet variables needed for our image
ENV CGO_ENABLED=0 \
GOOS=linux
Expand Down

0 comments on commit 69fab9f

Please sign in to comment.