Build Push Prune #243
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: Build Push Prune | |
on: | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: "0 6 * * *" # 6am everyday. | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
ACCOUNT: pangtao22 | |
BASE_IMAGE_NAME: quasistatic_simulator_base | |
IMAGE_NAME: quasistatic_simulator | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
submodules: recursive | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract base Docker metadata | |
id: meta_base | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.ACCOUNT }}/${{ env.BASE_IMAGE_NAME }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.ACCOUNT }}/${{ env.IMAGE_NAME }} | |
- name: Build and push Base Docker image | |
id: build-and-push-base | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./setup/base.dockerfile | |
push: true | |
tags: ${{ steps.meta_base.outputs.tags }} | |
labels: ${{ steps.meta_base.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./setup/qsim.dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
prune: | |
runs-on: ubuntu-latest | |
needs: build_and_push | |
steps: | |
- name: Prune base | |
uses: vlaurin/action-ghcr-prune@v0.5.0 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
user: ${{ github.actor }} | |
container: ${{ env.BASE_IMAGE_NAME }} | |
dry-run: false # Dry-run first, then change to `false` | |
prune-untagged: true | |
keep-younger-than: 7 | |
- name: Prune | |
uses: vlaurin/action-ghcr-prune@v0.5.0 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
user: ${{ github.actor }} | |
container: ${{ env.IMAGE_NAME }} | |
dry-run: false # Dry-run first, then change to `false` | |
keep-tags-regexes: | | |
tro$ | |
prune-untagged: true | |
keep-younger-than: 7 |