-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docker and apptainer image building on demand #176
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
90e579f
build docker and apptainer images on demand
mikemhenry ee31652
docker file to build image
mikemhenry d37c0bf
use latest image version and install pytest
mikemhenry c534b34
don't need to trim v from tag
mikemhenry b0dee91
run when we push to this branch so we can test
mikemhenry ab876a0
latest tag and version are the same
mikemhenry 4820a01
bash mistake
mikemhenry 9c76e2a
bump ci
mikemhenry ea2b2bc
Merge branch 'main' into feat/add_docker_and_apptainer
mikemhenry f8f0686
bump ci
mikemhenry 01a8287
Merge remote-tracking branch 'refs/remotes/origin/feat/add_docker_and…
mikemhenry 1656887
typo in docker file location
mikemhenry 08f1f4d
See if this frees up enough sapce
mikemhenry cd9fcfd
Update .github/workflows/docker.yaml
mikemhenry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# 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 | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
defaults: | ||
run: | ||
shell: bash -l {0} | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: choderalab/espaloma | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Free disk space | ||
run: | | ||
run: | | ||
sudo docker rmi $(docker image ls -aq) >/dev/null 2>&1 || true | ||
sudo rm -rf \ | ||
/usr/share/dotnet /usr/local/lib/android /opt/ghc \ | ||
/usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \ | ||
/usr/lib/jvm || true | ||
echo "some directories deleted" | ||
sudo apt install aptitude -y >/dev/null 2>&1 | ||
sudo aptitude purge aria2 ansible azure-cli shellcheck rpm xorriso zsync \ | ||
esl-erlang firefox gfortran-8 gfortran-9 google-chrome-stable \ | ||
google-cloud-sdk imagemagick \ | ||
libmagickcore-dev libmagickwand-dev libmagic-dev ant ant-optional kubectl \ | ||
mercurial apt-transport-https mono-complete libmysqlclient \ | ||
unixodbc-dev yarn chrpath libssl-dev libxft-dev \ | ||
libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev \ | ||
snmp pollinate libpq-dev postgresql-client powershell ruby-full \ | ||
sphinxsearch subversion mongodb-org azure-cli microsoft-edge-stable \ | ||
-y -f >/dev/null 2>&1 | ||
sudo aptitude purge google-cloud-sdk -f -y >/dev/null 2>&1 | ||
sudo aptitude purge microsoft-edge-stable -f -y >/dev/null 2>&1 || true | ||
sudo apt purge microsoft-edge-stable -f -y >/dev/null 2>&1 || true | ||
sudo aptitude purge '~n ^mysql' -f -y >/dev/null 2>&1 | ||
sudo aptitude purge '~n ^php' -f -y >/dev/null 2>&1 | ||
sudo aptitude purge '~n ^dotnet' -f -y >/dev/null 2>&1 | ||
sudo apt-get autoremove -y >/dev/null 2>&1 | ||
sudo apt-get autoclean -y >/dev/null 2>&1 | ||
echo "some packages purged" | ||
|
||
- 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 | ||
VERSION=$LATEST_TAG | ||
echo $VERSION | ||
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | ||
|
||
- name: Print Latest Version | ||
run: echo ${{ steps.latest-version.outputs.VERSION }} | ||
|
||
# Now that we got the version, we don't need the .git folder | ||
- name: Get more space | ||
run: | | ||
df . -h | ||
sudo rm -rf ${GITHUB_WORKSPACE}/.git | ||
df . -h | ||
|
||
- 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 | ||
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: | | ||
docker run --rm ${{ steps.fqirp.outputs.FQIRP }} python -c "import espaloma; print(espaloma.__version__)" | ||
docker run --rm ${{ steps.fqirp.outputs.FQIRP }} pytest --pyargs espaloma -v | ||
|
||
- name: Push Docker image | ||
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | ||
with: | ||
context: . | ||
file: docker/Dockerfile | ||
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 espaloma_${{ 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 ../espaloma_${{ steps.latest-version.outputs.VERSION }}.sif pytest --pyargs espaloma -v | ||
echo ${{ secrets.GITHUB_TOKEN }} | singularity remote login -u ${{ secrets.GHCR_USERNAME }} --password-stdin oras://ghcr.io | ||
singularity push ../espaloma_${{ steps.latest-version.outputs.VERSION }}.sif oras://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.latest-version.outputs.VERSION }}-apptainer |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM mambaorg/micromamba:1.4.9 | ||
|
||
LABEL org.opencontainers.image.source=https://github.com/choderalab/espaloma | ||
LABEL org.opencontainers.image.description="Extensible Surrogate Potential of Ab initio Learned and Optimized by Message-passing Algorithm" | ||
LABEL org.opencontainers.image.licenses=MIT | ||
# OpenFE Version we want to build | ||
ARG VERSION | ||
|
||
# Don't buffer stdout & stderr streams, so if there is a crash no partial buffer output is lost | ||
# https://docs.python.org/3/using/cmdline.html#cmdoption-u | ||
ENV PYTHONUNBUFFERED=1 | ||
|
||
RUN micromamba install -y -n base -c conda-forge -c dglteam pytest "dgl<1" git "espaloma==$VERSION" && \ | ||
micromamba clean --all --yes | ||
|
||
# Ensure that conda environment is automatically activated | ||
# https://github.com/mamba-org/micromamba-docker#running-commands-in-dockerfile-within-the-conda-environment | ||
ARG MAMBA_DOCKERFILE_ACTIVATE=1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a lot of things that have to be remove/purged from the ubuntu image, I wonder if we should eventually try a lighter docker image for our purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually running on the host, not inside the image. The image we base on is quite small, but the host has a TON of stuff, so I found that I ran out of space when building the singularity image after building the docker image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, I did notice that after I wrote my comment, but I guess the point still stands that we might want to use something smaller compared to
ubuntu-latest
for the host (even though I know this could change many things for us, just something to keep in mind in the future)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From here https://github.com/actions/runner-images#available-images and skimming that page, I don't think github plans on making any minimal images
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok, then this is as good as it gets! :) Thanks for checking that out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem! Thanks for giving me the idea to check!