From 33eb7bcf8844c1cf9f0f31c70e976d50046412ee Mon Sep 17 00:00:00 2001 From: Mike Henry <11765982+mikemhenry@users.noreply.github.com> Date: Thu, 29 Jun 2023 10:36:05 -0700 Subject: [PATCH] support a dev build as well --- .github/workflows/docker-dev.yaml | 133 ++++++++++++++++++++++++++++++ .github/workflows/docker.yaml | 6 +- 2 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/docker-dev.yaml diff --git a/.github/workflows/docker-dev.yaml b/.github/workflows/docker-dev.yaml new file mode 100644 index 000000000..d1846bfce --- /dev/null +++ b/.github/workflows/docker-dev.yaml @@ -0,0 +1,133 @@ +# 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. + +# GitHub recommends pinning actions to a commit SHA. +# To get a newer version, you will need to update the SHA. +# You can also reference a tag or branch, but the action may change without warning. + +name: Create and publish a Docker image (dev) + +on: + push: + branches: + - feat/improve_docker_building + tags: + - '*' # Build on pushes with tags (unless they contain a / ) + workflow_dispatch: + +defaults: + run: + shell: bash -l {0} + +env: + REGISTRY: ghcr.io + IMAGE_NAME: choderalab/perses + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Get Latest Version + id: latest-version + run: | + LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) + echo $LATEST_TAG + echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT + # In this case the version is the same as the latest_tag + VERSION=$LATEST_TAG + echo $VERSION + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + + - name: Print Latest Version + run: echo ${{ steps.latest-version.outputs.VERSION }} + + - name: Create fully qualified image registry path + id: fqirp + run: | + FQIRP=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.latest-version.outputs.VERSION }} + echo "FQIRP=$FQIRP" >> $GITHUB_OUTPUT + + - name: Print FQIRP + run: echo ${{ steps.fqirp.outputs.FQIRP }} + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=schedule,pattern=nightly,enable=true,priority=1000 + type=ref,event=branch,enable=true,priority=600 + type=ref,event=tag,enable=true,priority=600 + type=ref,event=pr,prefix=pr-,enable=true,priority=600 + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{version}} + type=sha + ${{ steps.latest-version.outputs.VERSION }} + + - name: Build and export to Docker + uses: docker/build-push-action@v4 + with: + context: . + file: docker/Dockerfile-dev + load: true + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=${{ steps.latest-version.outputs.VERSION }} + + - name: Test image + run: | + mkdir oe_license_dir + # Write out license to a file + echo "${{ secrets.OE_LICENSE }}" > oe_license_dir/oe_license.txt + docker run --rm ${{ steps.fqirp.outputs.FQIRP }} perses-cli --help + # Mount oe_license_dir (which should have the license file) to /openeye on container for testing + #docker run -e GITHUB_ACTIONS=true --mount type=bind,source=$PWD/oe_license_dir/,target=/openeye/,readonly --rm ${{ steps.fqirp.outputs.FQIRP }} pytest --pyargs perses -a "not advanced" -n auto -m "not gpu_needed" -v + + - name: Push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + file: docker/Dockerfile-dev + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=${{ steps.latest-version.outputs.VERSION }} + + - name: Setup Apptainer + uses: eWaterCycle/setup-apptainer@v2 + with: + apptainer-version: 1.1.2 + + - name: Build Apptainer Image + run: singularity build perses_${{ steps.latest-version.outputs.VERSION }}.sif docker-daemon:${{ steps.fqirp.outputs.FQIRP }} + + - name: Test & Push Apptainer Image + run: | + mkdir test_apptainer + cd test_apptainer + singularity run ../perses_${{ steps.latest-version.outputs.VERSION }}.sif perses-cli --help + singularity run --bind $PWD/oe_license_dir/:/openeye/ --env "GITHUB_ACTIONS=true" ../perses_${{ steps.latest-version.outputs.VERSION }}.sif pytest --pyargs perses -a "not advanced" -n auto -m "not gpu_needed" -v + echo ${{ secrets.GITHUB_TOKEN }} | singularity remote login -u ${{ secrets.GHCR_USERNAME }} --password-stdin oras://ghcr.io + singularity push ../perses_${{ steps.latest-version.outputs.VERSION }}.sif oras://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.latest-version.outputs.VERSION }}-apptainer diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index d1846bfce..468671de7 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -87,7 +87,7 @@ jobs: uses: docker/build-push-action@v4 with: context: . - file: docker/Dockerfile-dev + file: docker/Dockerfile load: true push: false tags: ${{ steps.meta.outputs.tags }} @@ -102,13 +102,13 @@ jobs: echo "${{ secrets.OE_LICENSE }}" > oe_license_dir/oe_license.txt docker run --rm ${{ steps.fqirp.outputs.FQIRP }} perses-cli --help # Mount oe_license_dir (which should have the license file) to /openeye on container for testing - #docker run -e GITHUB_ACTIONS=true --mount type=bind,source=$PWD/oe_license_dir/,target=/openeye/,readonly --rm ${{ steps.fqirp.outputs.FQIRP }} pytest --pyargs perses -a "not advanced" -n auto -m "not gpu_needed" -v + docker run -e GITHUB_ACTIONS=true --mount type=bind,source=$PWD/oe_license_dir/,target=/openeye/,readonly --rm ${{ steps.fqirp.outputs.FQIRP }} pytest --pyargs perses -a "not advanced" -n auto -m "not gpu_needed" -v - name: Push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: context: . - file: docker/Dockerfile-dev + file: docker/Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}