ci: Add docker image build #8
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: Docker Build | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
paths: | |
- "src/**" | |
- "tests/**" | |
- "resources/docker/Dockerfile" | |
- "resources/docker/*.lock" | |
- "resources/docker/*.yaml" | |
- "resources/docker/*.sh" | |
pull_request: | |
branches: | |
- "dev-**" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
FORCE_COLOR: 3 | |
DOCKER_REGISTRY: ghcr.io | |
DOCKER_ORG: ${{ github.repository_owner }} | |
GITHUB_SHA: ${{ github.sha }} | |
GITHUB_REF: ${{ github.ref }} | |
GITHUB_HEAD_REF: ${{ github.head_ref }} | |
GITHUB_REF_NAME: ${{ github.ref_name }} | |
PROJECT_NAME: caustics | |
jobs: | |
build-images: | |
name: build-image | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
fail-fast: false | |
matrix: | |
# Currently need to be hardcoded | |
# for more version, will need to modify | |
# the conda environment to be able | |
# to install different versions of CUDA | |
CUDA_VERSION: ["11.8.0"] | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Get registry and org | |
id: registry_org | |
run: | | |
ORG=$(echo "${DOCKER_ORG}" | tr '[:upper:]' '[:lower:]') | |
echo "image_base=${DOCKER_REGISTRY}/${ORG}" >> $GITHUB_OUTPUT | |
- name: Get short github sha | |
id: github_sha | |
run: | | |
SHA7="${GITHUB_SHA::7}" | |
echo "short_sha=${SHA7}" >> $GITHUB_OUTPUT | |
- name: Extract branch name | |
id: extract_branch | |
run: | |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> | |
$GITHUB_OUTPUT | |
# https://github.com/actions/runner-images/issues/2840#issuecomment-790492173 | |
- name: Free up disk space | |
run: | | |
df -h | |
docker image ls | |
sudo apt clean | |
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc | |
df -h | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | |
${{ steps.registry_org.outputs.image_base }}/${{ env.PROJECT_NAME }} | |
tags: | | |
type=raw,value=${{ steps.extract_branch.outputs.branch }}-cuda-${{ matrix.CUDA_VERSION }} | |
type=raw,value=${{ steps.github_sha.outputs.short_sha }}-cuda-${{ matrix.CUDA_VERSION }} | |
- name: Log in to registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.DOCKER_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and export to Docker | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./resources/docker/Dockerfile | |
platforms: linux/amd64 | |
load: ${{ env.GITHUB_REF != 'refs/heads/main' }} | |
push: ${{ env.GITHUB_REF == 'refs/heads/main' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
CAUSTICS_VERSION=${{ steps.extract_branch.outputs.branch }} | |
CUDA_VERSION=${{ matrix.CUDA_VERSION }} | |
- name: Inspect Image | |
if: ${{ env.GITHUB_REF != 'refs/heads/main' }} | |
run: | | |
docker run ${{ steps.registry_org.outputs.image_base }}/${{ env.PROJECT_NAME }}:${{ steps.github_sha.outputs.short_sha }}-cuda-${{ matrix.CUDA_VERSION }} micromamba list | |
docker image ls |