chore(docker): improve docker build workflow

This commit is contained in:
Orhun Parmaksız 2021-10-12 19:46:32 +03:00
parent dcaa5eccf9
commit 8eff8847ea
No known key found for this signature in database
GPG Key ID: F83424824B3E4B90
3 changed files with 69 additions and 44 deletions

View File

@ -64,29 +64,3 @@ jobs:
with:
command: publish
args: --locked --token ${{ secrets.CARGO_TOKEN }}
publish-docker:
name: Publish the Docker image
needs: publish-github
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@master
- name: Set the release version
run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV
- name: Build
run: docker build -t rustypaste .
- name: Tag
run: |
docker tag rustypaste orhunp/rustypaste:${{ env.RELEASE_VERSION }}
docker tag rustypaste docker.pkg.github.com/orhun/rustypaste/rustypaste:${{ env.RELEASE_VERSION }}
- name: Login (Docker Hub)
run: echo ${{ secrets.DOCKER_TOKEN }} |
docker login -u orhunp --password-stdin
- name: Push (Docker Hub)
run: docker push orhunp/rustypaste:${{ env.RELEASE_VERSION }}
- name: Login (Package Registry)
run: echo ${{ secrets.GITHUB_TOKEN }} |
docker login -u orhun docker.pkg.github.com --password-stdin
- name: Push (Package Registry)
run: docker push docker.pkg.github.com/orhun/rustypaste/rustypaste:${{ env.RELEASE_VERSION }}

View File

@ -7,6 +7,8 @@ on:
pull_request:
branches:
- master
schedule:
- cron: "0 0 * * 0"
jobs:
check:

View File

@ -4,27 +4,76 @@ on:
push:
branches:
- master
tags:
- "v*.*.*"
pull_request:
branches:
- master
schedule:
- cron: "0 0 * * 0"
jobs:
docker:
name: Docker
name: Docker Build and Push
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@master
- name: Build
run: docker build -t rustypaste .
- name: Tag
run: |
docker tag rustypaste orhunp/rustypaste:latest
docker tag rustypaste docker.pkg.github.com/orhun/rustypaste/rustypaste:latest
- name: Login (Docker Hub)
run: echo ${{ secrets.DOCKER_TOKEN }} |
docker login -u orhunp --password-stdin
- name: Push (Docker Hub)
run: docker push orhunp/rustypaste:latest
- name: Login (Package Registry)
run: echo ${{ secrets.GITHUB_TOKEN }} |
docker login -u orhun docker.pkg.github.com --password-stdin
- name: Push (Package Registry)
run: docker push docker.pkg.github.com/orhun/rustypaste/rustypaste:latest
uses: actions/checkout@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
orhunp/rustypaste
ghcr.io/${{ github.repository_owner }}/rustypaste/rustypaste
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=sha
type=raw,value=latest
type=semver,pattern={{version}}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: orhunp
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}