Rust bindings #48
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: Docker build | |
on: | |
pull_request: | |
types: | |
- "opened" | |
- "reopened" | |
- "synchronize" | |
push: | |
paths-ignore: | |
- "docs" | |
- "tests" | |
- ".github" | |
jobs: | |
buildx: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# Set derived configuration variables: | |
# - images: images to build (docker and/or github) | |
# - push: if images need to be uploaded to repository (when secrets available) | |
# - has_docker_token | |
# - has_github_token | |
# - cache_from: image tag to use for imported cache | |
# - cache_to: image tag to use for exported cache | |
# - github_server_url: reference to source code repository | |
- name: Prepare | |
id: prep | |
run: | | |
IMAGES="" | |
PUSH=false | |
if [ -n "${{ secrets.DOCKERHUB_TOKEN }}" ]; then | |
IMAGES="gameonwhales/inputtino" | |
PUSH=true | |
echo "has_docker_token=true" >> $GITHUB_OUTPUT | |
fi | |
if [ -n "${{ secrets.GHCR_TOKEN }}" ]; then | |
REGISTRY_IMAGE="ghcr.io/${{ github.repository_owner }}/inputtino" | |
if [ "$IMAGES" = "" ]; then | |
IMAGES="ghcr.io/${REGISTRY_IMAGE}" | |
else | |
IMAGES="$IMAGES,ghcr.io/${REGISTRY_IMAGE}" | |
fi | |
PUSH=true | |
echo "has_github_token=true" >> $GITHUB_OUTPUT | |
echo "cache_from=type=registry,ref=${REGISTRY_IMAGE}:buildcache" >> $GITHUB_OUTPUT | |
echo "cache_to=type=registry,ref=${REGISTRY_IMAGE}:buildcache,mode=max" >> $GITHUB_OUTPUT | |
else | |
echo "cache_from=type=registry,ref=${REGISTRY_IMAGE}:buildcache" >> $GITHUB_OUTPUT | |
echo "cache_to=" >> $GITHUB_OUTPUT | |
fi | |
# No token present, might be a PR. Allow build without push | |
if [ "$IMAGES" = "" ]; then | |
IMAGES="gameonwhales/inputtino" | |
PUSH=false | |
fi | |
echo "images=${IMAGES}" >> $GITHUB_OUTPUT | |
echo "push=${PUSH}" >> $GITHUB_OUTPUT | |
echo "github_server_url=${GITHUB_SERVER_URL}" >> $GITHUB_OUTPUT | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
# list of Docker images to use as base name for tags | |
images: ${{ steps.prep.outputs.images }} | |
# generate Docker tags based on the following events/attributes | |
tags: | | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}} | |
type=edge,branch=master | |
type=ref,event=branch | |
type=raw,value=alpha | |
type=sha | |
flavor: latest=false # let's not produce a :latest tag | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
install: true | |
version: latest | |
driver-opts: image=moby/buildkit:master | |
- name: Login to DockerHub | |
if: steps.prep.outputs.has_docker_token != '' # secrets not available in PRs | |
uses: docker/login-action@v2 | |
with: | |
username: abeltramo | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
if: steps.prep.outputs.has_github_token != '' # secrets not available in PRs | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Build inputtino | |
uses: docker/build-push-action@v3 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
context: . | |
file: docker/web-server.Dockerfile | |
push: ${{ steps.prep.outputs.push }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
BASE_IMAGE=ghcr.io/games-on-whales/base:edge | |
IMAGE_SOURCE=${{ steps.prep.outputs.github_server_url }}/${{ github.repository }} | |
cache-from: ${{ steps.prep.outputs.cache_from }} | |
cache-to: ${{ steps.prep.outputs.cache_to }} |