From 19d13d9ffb91c847dcf6761d2fbdec6b203ab958 Mon Sep 17 00:00:00 2001 From: Nathan Dias Date: Fri, 2 Sep 2022 18:21:15 -0500 Subject: [PATCH] .github: add actions to build and release docker image on ghcr (#35) --- .github/workflows/build-image.yaml | 20 +++++++++ .github/workflows/release.yml | 67 ++++++++++++++++-------------- Makefile | 2 +- 3 files changed, 57 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/build-image.yaml diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml new file mode 100644 index 0000000..e1c3261 --- /dev/null +++ b/.github/workflows/build-image.yaml @@ -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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a8676df..9f13f9b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/Makefile b/Makefile index 5ac0596..7ac1f3f 100644 --- a/Makefile +++ b/Makefile @@ -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