Main to dev #253
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 | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
release: | |
types: | |
- published | |
pull_request: | |
env: | |
MAIN_REPO: IN-CORE/incore-lab | |
GITHUB_PUSH: "true" | |
jobs: | |
# ---------------------------------------------------------------------- | |
# HUB | |
# ---------------------------------------------------------------------- | |
docker: | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
strategy: | |
fail-fast: false | |
matrix: | |
name: | |
- hub | |
- lab | |
steps: | |
# checkout source code | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # ensure full repo is checked out | |
# calculate component version information | |
- name: component version information | |
run: | | |
CHANNEL=$(cat lab/config.yml | grep "Channel" | head -1 | awk -F ": " '{print $2}' | sed 's/["[:space:]]//g') | |
INCORE_VERSION=$(cat lab/config.yml | grep "INCORE_VERSION" | head -1 | awk -F= "{print $2 }" | sed "s/[[:alpha:]|,|-|\"|:|#|[:space:]_]//g" | sed "s/-//g") | |
PYINCORE_VERSION=$(cat lab/config.yml | grep "PyIncore" | head -1 | awk -F: '{print $2}' | tr -d '"|[:space:]' | sed 's/-//g') | |
PYINCORE_VIZ_VERSION=$(cat lab/config.yml | grep "PyIncore-Viz" | head -1 | awk -F: '{print $2}' | tr -d '"|[:space:]' | sed 's/-//g') | |
PYINCORE_DATA_VERSION=$(cat lab/config.yml | grep "PyIncore-Data" | head -1 | awk -F: '{print $2}' | tr -d '"|[:space:]' | sed 's/-//g') | |
echo "CHANNEL=${CHANNEL}" >> $GITHUB_ENV | |
echo "INCORE_VERSION=${INCORE_VERSION}" >> $GITHUB_ENV | |
echo "PYINCORE_VERSION=${PYINCORE_VERSION}" >> $GITHUB_ENV | |
echo "PYINCORE_VIZ_VERSION=${PYINCORE_VIZ_VERSION}" >> $GITHUB_ENV | |
echo "PYINCORE_DATA_VERSION=${PYINCORE_DATA_VERSION}" >> $GITHUB_ENV | |
# calculate branch version information | |
- name: version information | |
run: | | |
echo ${GITHUB_REF_NAME} | |
if [ "${{ github.event.release.target_commitish }}" != "" ]; then | |
BRANCH="${{ github.event.release.target_commitish }}" | |
elif [[ $GITHUB_REF =~ pull ]]; then | |
BRANCH="$(echo $GITHUB_REF | sed 's#refs/pull/\([0-9]*\)/merge#PR-\1#')" | |
else | |
BRANCH=${GITHUB_REF_NAME} | |
fi | |
# should we push to dockerhub, and is there a README | |
DOCKERHUB_PUSH="false" | |
DOCKERHUB_README="false" | |
#if [ "${{ github.repository }}" == "${{ env.MAIN_REPO }}" ]; then | |
# if [ "${{ secrets.DOCKERHUB_USERNAME }}" != "" -a "${{ secrets.DOCKERHUB_PASSWORD }}" != "" ]; then | |
# DOCKERHUB_PUSH="true" | |
# if [ -e "${{ matrix.FOLDER }}/README.md" ]; then | |
# DOCKERHUB_README="true" | |
# fi | |
# fi | |
#fi | |
# should we push to NCSA | |
NCSAHUB_PUSH="false" | |
if [ "${{ github.repository }}" == "${{ env.MAIN_REPO }}" ]; then | |
if [ "${{ secrets.HUB_USERNAME }}" != "" -a "${{ secrets.HUB_PASSWORD }}" != "" ]; then | |
NCSAHUB_PUSH="true" | |
fi | |
fi | |
# figure out the versions | |
if [ "$BRANCH" == "main" ]; then | |
version=$(awk '/^## / { print tolower($2) }' CHANGELOG.md | head -1 | sed 's/^.//;s/.$//') | |
tags="latest" | |
oldversion="" | |
while [ "${oldversion}" != "${version}" ]; do | |
oldversion="${version}" | |
tags="${tags} ${version}" | |
version=${version%.*} | |
done | |
version="$(awk '/^## / { print tolower($2) }' CHANGELOG.md | head -1)" | |
elif [ "$BRANCH" == "develop" ]; then | |
version="develop" | |
tags="develop" | |
else | |
version="test" | |
tags="${BRANCH}" | |
fi | |
push_tags="" | |
OWNER=${GITHUB_REPOSITORY_OWNER,,} | |
for tag in ${tags}; do | |
if [ "${DOCKERHUB_PUSH}" == "true" ]; then | |
push_tags="${push_tags}incore/jupyterhub:${tag}," | |
fi | |
if [ "${NCSAHUB_PUSH}" == "true" ]; then | |
push_tags="${push_tags}hub.ncsa.illinois.edu/incore/${{ matrix.name }}:${tag}," | |
fi | |
if [ "${GITHUB_PUSH}" == "true" ]; then | |
push_tags="${push_tags}ghcr.io/${OWNER}/${{ matrix.name }}:${tag}," | |
fi | |
done | |
push_tags="${push_tags%,*}" | |
echo "BRANCH=${BRANCH}" | |
echo "VERSION=${version}" | |
echo "TAGS=${tags}" | |
echo "PUSH_TAGS=${push_tags}" | |
echo "DOCKERHUB_PUSH=${DOCKERHUB_PUSH}" >> $GITHUB_ENV | |
echo "DOCKERHUB_README=${DOCKERHUB_README}" >> $GITHUB_ENV | |
echo "NCSAHUB_PUSH=${NCSAHUB_PUSH}" >> $GITHUB_ENV | |
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV | |
echo "VERSION=${version}" >> $GITHUB_ENV | |
echo "TAGS=${push_tags}" >> $GITHUB_ENV | |
# print version information | |
- name: Print Version information | |
run: | | |
echo "${{ env.TAGS }}" | |
echo "${{ env.CHANNEL }}" | |
echo "Incore: ${{ env.INCORE_VERSION }}" | |
echo "PyIncore: ${{ env.PYINCORE_VERSION }}" | |
echo "PyIncore-Viz: ${{ env.PYINCORE_VIZ_VERSION }}" | |
echo "PyIncore-Data: ${{ env.PYINCORE_DATA_VERSION }}" | |
# setup docker build | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Inspect Builder | |
run: | | |
echo "Name: ${{ steps.buildx.outputs.name }}" | |
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" | |
echo "Status: ${{ steps.buildx.outputs.status }}" | |
echo "Flags: ${{ steps.buildx.outputs.flags }}" | |
echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | |
# login to registries | |
- name: Login to DockerHub | |
if: env.DOCKERHUB_PUSH == 'true' | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Login to NCSA | |
if: env.NCSAHUB_PUSH == 'true' | |
uses: docker/login-action@v2 | |
with: | |
registry: hub.ncsa.illinois.edu | |
username: ${{ secrets.HUB_USERNAME }} | |
password: ${{ secrets.HUB_PASSWORD }} | |
- name: Login to GitHub Container Registry | |
if: env.GITHUB_PUSH == 'true' | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# build and push docker images | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
push: true | |
platforms: "linux/amd64" | |
file: ${{ matrix.name }}/Dockerfile | |
cache-from: type=gha,scope=${{ env.BRANCH }}-${{ matrix.name }} | |
cache-to: type=gha,scope=${{ env.BRANCH }}-${{ matrix.name }},mode=max | |
tags: ${{ env.TAGS }} | |
build-args: | | |
INCORE=${{ env.INCORE_VERSION }} | |
PYINCORE=${{ env.PYINCORE_VERSION }} | |
PYINCORE_VIZ=${{ env.PYINCORE_VIZ_VERSION }} | |
PYINCORE_DATA=${{ env.PYINCORE_DATA_VERSION }} | |
CHANNEL=${{ env.CHANNEL }} | |
# update README at DockerHub | |
# - name: Docker Hub Description | |
# if: env.dockerhub != '' && matrix.README != '' && github.event_name == 'push' && github.repository == env.MASTER_REPO && env.BRANCH == 'master' | |
# uses: peter-evans/dockerhub-description@v2 | |
# env: | |
# DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
# DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | |
# DOCKERHUB_REPOSITORY: ${{ env.DOCKERHUB_ORG }}/${{ matrix.IMAGE }} | |
# README_FILEPATH: ${{ matrix.README }} |