Docker #128
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 | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
on: | |
schedule: | |
- cron: '31 0 * * *' | |
workflow_dispatch: | |
push: | |
branches: [ "main" ] | |
# Publish semver tags as releases. | |
tags: [ 'v*.*.*' ] | |
pull_request: | |
branches: [ "main" ] | |
env: | |
# Uses docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
# Rust nightly toolchain version | |
NIGHTLY_VERSION: ${{ vars.NIGHTLY_VERSION }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Build container | |
shell: bash | |
run: docker build --pull -t build_image . --build-arg NIGHTLY_VERSION=${{ env.NIGHTLY_VERSION }} | |
- name: Tag nightly | |
if: github.event_name != 'pull_request' | |
shell: bash | |
run: docker tag build_image "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly" | |
# Login against a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Push Docker image (don't push on PR) | |
- name: Publish | |
if: github.event_name != 'pull_request' | |
shell: bash | |
run: | | |
docker image push --all-tags "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" |