Skip to content

Commit

Permalink
.github: add actions to build and release docker image on ghcr (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirbyquerby authored Sep 2, 2022
1 parent eff6662 commit 19d13d9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 32 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build Docker image

on:
pull_request:

env:
GO_VERSION: 1.17

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
build-args: GO_VERSION=${{ env.GO_VERSION }}
67 changes: 36 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
name: Release
name: Create and publish a Docker image

on:
push:
tags:
- 'v*'
release:
types: [published]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
GO_VERSION: 1.17

jobs:
build:
build-and-push-image:
runs-on: ubuntu-latest
env:
GO111MODULE: on
permissions:
contents: read
packages: write

steps:
- name: Checkout Source
uses: actions/checkout@v2
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v2
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
go-version: 1.17.x
- name : Get release version
id: get_version
run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:10})
- name: Release Binaries
uses: goreleaser/goreleaser-action@v2
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release Docker Image
uses: elgohr/Publish-Docker-Github-Action@master
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
name: securego/gosec
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
buildargs: GO_VERSION=1.17
tags: "latest,${{ env.RELEASE_VERSION }}"
tag_names: true
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: GO_VERSION=${{ env.GO_VERSION }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT_TAG?= $(shell git describe --always --tags)
BIN = gosec
FMT_CMD = $(gofmt -s -l -w $(find . -type f -name '*.go' -not -path './vendor/*') | tee /dev/stderr)
IMAGE_REPO = securego
IMAGE_REPO = cosmos
BUILDFLAGS := '-w -s'
CGO_ENABLED = 0
GO := GO111MODULE=on go
Expand Down

0 comments on commit 19d13d9

Please sign in to comment.