Update Dockerfile #55
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 py-rocket-base image | |
on: | |
workflow_dispatch: null | |
push: | |
branches: | |
- main | |
paths: | |
- 'apt.txt' | |
- 'user-dirs.dirs' | |
- 'vscode-extensions.txt' | |
- 'environment.yml' | |
- 'start' | |
- 'postBuild' | |
- 'Dockerfile' | |
- 'custom_jupyter_server_config.json' | |
- 'scripts/**' | |
- '.github/workflows/build.yaml' | |
- '!book/**' # Ignore all changes in the /book directory | |
- '!docs/**' # Ignore all changes in the /docs directory | |
- '!base-image/**' | |
- '!README.md' | |
- '!conda-lock.yml' | |
- '!LICENSE' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: write-all | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: main | |
- name: Login to GitHub Container Registry | |
if: github.repository == 'nmfs-opensci/py-rocket-base' | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{github.actor}} | |
password: ${{secrets.GITHUB_TOKEN}} | |
- name: Create short_sha tag | |
shell: bash | |
run: | | |
short_sha=$(echo "${{ github.sha }}" | cut -c1-7) | |
echo "tag=${short_sha}" >> $GITHUB_ENV | |
- name: Extract VERSION from Dockerfile | |
shell: bash | |
run: | | |
# Check for both OCI-compliant version label and generic version label | |
if grep -q "LABEL org.opencontainers.image.version=" Dockerfile; then | |
version=$(grep "LABEL org.opencontainers.image.version=" Dockerfile | cut -d '=' -f 2 | tr -d ' ') | |
elif grep -q "LABEL VERSION=" Dockerfile; then | |
version=$(grep "LABEL VERSION=" Dockerfile | cut -d '=' -f 2 | tr -d ' ') | |
else | |
version="" | |
fi | |
echo "version=${version}" >> $GITHUB_ENV | |
- name: Build the Docker image | |
if: github.repository == 'nmfs-opensci/py-rocket-base' | |
run: | | |
docker build . -f Dockerfile \ | |
--tag ghcr.io/nmfs-opensci/py-rocket-base:latest \ | |
--tag ghcr.io/nmfs-opensci/py-rocket-base:${{ env.tag }} | |
# If VERSION exists, tag the image with that as well | |
if [ -n "${{ env.version }}" ]; then | |
docker tag ghcr.io/nmfs-opensci/py-rocket-base:${{ env.tag }} ghcr.io/nmfs-opensci/py-rocket-base:${{ env.version }} | |
fi | |
- name: Publish | |
if: github.repository == 'nmfs-opensci/py-rocket-base' | |
run: | | |
docker push ghcr.io/nmfs-opensci/py-rocket-base:latest | |
docker push ghcr.io/nmfs-opensci/py-rocket-base:${{ env.tag }} | |
# Push the version tag if it exists | |
if [ -n "${{ env.version }}" ]; then | |
docker push ghcr.io/nmfs-opensci/py-rocket-base:${{ env.version }} | |
fi |