Fix post errors (#21) #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: functions build and publish | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: | |
- "*" | |
jobs: | |
docker-build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
with: | |
fetch-depth: 1 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@master | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@master | |
# remove me after testing | |
- name: Get TAG | |
id: git_tag | |
run: echo "GIT_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_ENV | |
- name: Check Tag Output | |
run: | | |
echo "GIT_TAG=${{env.GIT_TAG}}" | |
- name: Get TAG | |
id: get_tag | |
run: echo TAG=${{ github.sha }} >> $GITHUB_ENV | |
- name: Check Tag Output | |
run: | | |
echo "${{env.TAG}}" | |
- name: Login to Docker Hub | |
uses: docker/login-action@master | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Cache Docker layers | |
uses: actions/cache@master | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Build and export to Docker | |
uses: docker/build-push-action@master | |
with: | |
context: . | |
file: ./Dockerfile | |
load: true | |
tags: ${{ env.TEST_TAG }} | |
- name: Build | |
uses: docker/build-push-action@master | |
with: | |
context: . | |
file: ./Dockerfile | |
push: false | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
tags: | | |
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest | |
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ env.TAG }} | |
# Publish when merging to main as latest and git sha | |
docker-push: | |
if: ${{ github.ref == 'refs/heads/main' }} | |
needs: docker-build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
with: | |
fetch-depth: 1 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@master | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@master | |
- name: Get TAG | |
id: get_tag | |
run: echo TAG=${{ github.sha }} >> $GITHUB_ENV | |
- name: Login to Docker Hub | |
uses: docker/login-action@master | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Cache Docker layers | |
uses: actions/cache@master | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Push to Registry | |
uses: docker/build-push-action@master | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
tags: | | |
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest | |
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ env.TAG }} | |
- # Temp fix | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
# only push when a new git tagged release is available | |
# will publish an image with git tag | |
docker-push-tag: | |
if: startsWith(github.event.ref, 'refs/tags/v') | |
needs: docker-build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
with: | |
fetch-depth: 1 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@master | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@master | |
- name: Get TAG | |
id: git_tag | |
run: echo "TAG=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_ENV | |
- name: Check Tag Output | |
run: | | |
echo "TAG=${{env.TAG}}" | |
- name: Login to Docker Hub | |
uses: docker/login-action@master | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Cache Docker layers | |
uses: actions/cache@master | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Push to Registry | |
uses: docker/build-push-action@master | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
tags: | | |
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ env.TAG }} | |
- # Temp fix | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |