From 2bd5e2a3c83cd66990a45d0a1b653d6210915d1d Mon Sep 17 00:00:00 2001 From: eikendev Date: Fri, 6 Aug 2021 16:59:35 +0200 Subject: [PATCH] Publish image to GitHub's registry --- .github/workflows/publish.yml | 39 ++++++++++++++++++++++++++++++----- Makefile | 8 ------- README.md | 2 +- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f41aa31..68bb79c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,29 +1,58 @@ name: Publish + on: push: tags: - 'v[0-9]+.[0-9]+.[0-9]+' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: test_build_publish: name: Test, build, and publish runs-on: ubuntu-latest + permissions: + contents: read + packages: write steps: - name: Checkout code uses: actions/checkout@v2 + - name: Export GOBIN uses: actions/setup-go@v2 with: go-version: 1.16 + - name: Install dependencies run: make setup + - name: Run tests run: make test + - name: Build image run: make build_image - - name: Login to Docker Hub + + - name: Log in to the Container registry uses: docker/login-action@v1 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Publish image - run: make push_image + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Makefile b/Makefile index 7bfcaa2..a10b2f6 100644 --- a/Makefile +++ b/Makefile @@ -20,11 +20,3 @@ test: setup: go install github.com/fzipp/gocyclo/cmd/gocyclo@latest go install honnef.co/go/tools/cmd/staticcheck@latest - -.PHONY: build_image -build_image: - docker build -t ${IMAGE}:latest . - -.PHONY: push_image -push_image: - docker push ${IMAGE}:latest diff --git a/README.md b/README.md index e2fc192..73ec9e9 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ version: '2' services: server: - image: eikendev/pushbits:latest + image: ghcr.io/pushbits/server:latest ports: - 8080:8080 environment: