Build neurodesktop-dev #211
Workflow file for this run
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 neurodesktop-dev | |
# Scheduled production builds at 17:00 UTC every day. | |
# Build manually from here: https://github.com/NeuroDesk/neurodesktop/actions/workflows/build-neurodesktop.yml | |
# DockerHub: https://hub.docker.com/r/vnmd/neurodesktop | |
# Github Packages: https://github.com/NeuroDesk/neurodesktop/pkgs/container/neurodesktop%2Fneurodesktop | |
on: | |
workflow_dispatch: | |
inputs: | |
force_push: | |
description: 'Force push?' | |
type: boolean | |
required: true | |
default: false | |
# schedule: | |
# - cron: '0 17 * * *' | |
env: | |
DOCKERHUB_ORG: ${{ vars.DOCKERHUB_ORG }} | |
OCIR_REPO: ${{ vars.OCIR_REPO }} | |
jobs: | |
build-image: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Fetch github api rate limit | |
run: | | |
GITHUB_RATE_REMAINING=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/rate_limit | jq '.rate.remaining') | |
echo "GITHUB_RATE_REMAINING=${GITHUB_RATE_REMAINING}" | |
echo "GITHUB_RATE_REMAINING=$GITHUB_RATE_REMAINING" >> $GITHUB_ENV | |
# - name: Maximize build space | |
# uses: easimon/maximize-build-space@master | |
# with: | |
# root-reserve-mb: 40000 | |
# swap-size-mb: 1024 | |
# overprovision-lvm: 'true' | |
# remove-dotnet: 'true' | |
# remove-android: 'true' | |
# remove-haskell: 'true' | |
# remove-codeql: 'true' | |
# remove-docker-images: 'true' | |
- name: Checkout repository | |
if: ${{ env.GITHUB_RATE_REMAINING > 0 }} | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.ref }} | |
- name: Set environment variables | |
if: ${{ env.GITHUB_RATE_REMAINING > 0 }} | |
run: | | |
IMAGENAME="neurodesktop-dev" | |
BUILDDATE=`date +%Y%m%dT%H%M` | |
SHORT_SHA=$(git rev-parse --short $GITHUB_SHA) | |
IMAGEID=ghcr.io/$GITHUB_REPOSITORY/$IMAGENAME | |
IMAGEID=$(echo $IMAGEID | tr '[A-Z]' '[a-z]') | |
echo "BUILDDATE=$BUILDDATE" | |
echo "SHORT_SHA=$SHORT_SHA" | |
echo "IMAGEID=$IMAGEID" | |
echo "IMAGENAME=$IMAGENAME" | |
echo "BUILDDATE=$BUILDDATE" >> $GITHUB_ENV | |
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV | |
echo "IMAGEID=$IMAGEID" >> $GITHUB_ENV | |
echo "IMAGENAME=$IMAGENAME" >> $GITHUB_ENV | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GHCR | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get cached image digest | |
run: | | |
docker pull $IMAGEID:latest && ROOTFS_CACHE=$(docker inspect --format='{{.RootFS}}' $IMAGEID:latest) && docker rmi $IMAGEID:latest || true | |
echo "ROOTFS_CACHE=$ROOTFS_CACHE" >> $GITHUB_ENV | |
- name: Build image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
load: true | |
tags: ${{ env.IMAGEID}}:${{ env.SHORT_SHA }} | |
cache-from: type=registry,ref=${{ env.IMAGEID}}:latest | |
cache-to: type=inline | |
- name: Get new image digest and generate tags | |
run: | | |
ROOTFS_NEW=$(docker inspect --format='{{.RootFS}}' $IMAGEID:$SHORT_SHA) | |
PUSH_TAGS="${IMAGEID}:${BUILDDATE}, ${IMAGEID}:latest" | |
if [ ! -z "${DOCKERHUB_ORG}" ]; then | |
docker tag ${IMAGEID}:${SHORT_SHA} ${DOCKERHUB_ORG}/${IMAGENAME}:${BUILDDATE} | |
docker tag ${IMAGEID}:${SHORT_SHA} ${DOCKERHUB_ORG}/${IMAGENAME}:latest | |
PUSH_TAGS="${PUSH_TAGS}, ${DOCKERHUB_ORG}/${IMAGENAME}:${BUILDDATE}, ${DOCKERHUB_ORG}/${IMAGENAME}:latest" | |
fi | |
if [ ! -z "${OCIR_REPO}" ]; then | |
docker tag ${IMAGEID}:${SHORT_SHA} "${OCIR_REPO}/${IMAGENAME}:${BUILDDATE}" | |
docker tag ${IMAGEID}:${SHORT_SHA} "${OCIR_REPO}/${IMAGENAME}:latest" | |
PUSH_TAGS="${PUSH_TAGS}, ${OCIR_REPO}/${IMAGENAME}:${BUILDDATE}, ${OCIR_REPO}/${IMAGENAME}:latest" | |
fi | |
echo "PUSH_TAGS=$PUSH_TAGS" | |
echo "ROOTFS_NEW=$ROOTFS_NEW" >> $GITHUB_ENV | |
echo "PUSH_TAGS=$PUSH_TAGS" >> $GITHUB_ENV | |
- name: Login to DockerHub (if changes found) | |
if: ${{ env.DOCKERHUB_ORG != '' && (env.ROOTFS_NEW != env.ROOTFS_CACHE || github.event.inputs.force_push == 'true') }} | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Login to OCIR (if changes found) | |
if: ${{ env.OCIR_REPO != '' && (env.ROOTFS_NEW != env.ROOTFS_CACHE || github.event.inputs.force_push == 'true') }} | |
uses: docker/login-action@v2 | |
with: | |
registry: syd.ocir.io | |
username: ${{ secrets.OCIR_USERNAME }} | |
password: ${{ secrets.OCIR_PASSWORD }} | |
- name: Push image (if changes found) | |
if: ${{ env.ROOTFS_NEW != env.ROOTFS_CACHE || github.event.inputs.force_push == 'true' }} | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
provenance: false # fixes unknown/unknown arch builds | |
push: true | |
tags: ${{ env.PUSH_TAGS}} | |
cache-from: type=registry,ref=${{ env.IMAGEID}}:latest | |
cache-to: type=inline | |
# - name: Container image scan | |
# if: ${{ env.GITHUB_RATE_REMAINING > 0 }} | |
# uses: aquasecurity/[email protected] | |
# with: | |
# image-ref: ${{ env.IMAGEID }} | |
# format: table | |
# exit-code: '1' | |
# severity: CRITICAL | |
# timeout: 25m0s | |
# skip-files: /opt/rclone-v1.60.1-linux-amd64/README.txt, /opt/rclone-v1.60.1-linux-amd64/README.html, /opt/rclone-v1.60.1-linux-amd64/rclone.1 | |
# - name: Generate issue on job failure | |
# if: always() && failure() | |
# uses: JasonEtco/create-an-issue@v2 | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# GITHUB_WORKFLOW: ${{ env.GITHUB_WORKFLOW }} | |
# GITHUB_SERVER_URL: ${{ env.GITHUB_SERVER_URL }} | |
# GITHUB_REPOSITORY: ${{ env.GITHUB_REPOSITORY }} | |
# GITHUB_RUN_ID: ${{ env.GITHUB_RUN_ID }} | |
# with: | |
# filename: .github/job_failure_issue_template.md | |
# update_existing: true | |
# search_existing: open |