Publish image to GitHub's registry

This commit is contained in:
eikendev 2021-08-06 16:59:35 +02:00
parent 90e98acba5
commit 2bd5e2a3c8
No known key found for this signature in database
GPG key ID: A1BDB1B28C8EF694
3 changed files with 35 additions and 14 deletions

View file

@ -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 }}

View file

@ -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

View file

@ -75,7 +75,7 @@ version: '2'
services:
server:
image: eikendev/pushbits:latest
image: ghcr.io/pushbits/server:latest
ports:
- 8080:8080
environment: