Skip to content
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

Create dockerhub_ci.yml #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions .github/workflows/dockerhub_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Dockerhub CI

on:
push:
branches:
- master
pull_request:
branches:
- master
schedule:
# Triggers every week on tuesday night
- cron: '0 0 * * 2'

env:
# Specify which image to build
DOCKER_REPO: godatadriven/jupyterhub

jobs:
build:
name: build
runs-on: ubuntu-latest
strategy:
matrix:
# Specify which tags to build
DOCKER_TAG: ["1.3.0-spark,latest", "1.3.0-nospark", "1.2.2-spark", "1.2.2-nospark", "1.1.0-spark", "1.1.0-nospark"]

timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Parse args
id: args
run: |
DOCKER_TAG="${{ matrix.DOCKER_TAG }}"
IMAGE_TAG="${DOCKER_TAG%%,*}"

# Manipulate DOCKER_TAG to create build args
JH_VERSION=${IMAGE_TAG%-*}
SPARK_VERSION=${IMAGE_TAG#*-}

if [ $SPARK_VERSION = "nospark" ]; then
DOCKER_FILE="./Dockerfile_NoSpark"
else
DOCKER_FILE="./Dockerfile"
fi

BUILD_ARGS="JH_VERSION=$JH_VERSION"

# No modification needed beyond this point
BUILD_ARGS="${BUILD_ARGS//'%'/'%25'}"
BUILD_ARGS="${BUILD_ARGS//$'\n'/'%0A'}"
BUILD_ARGS="${BUILD_ARGS//$'\r'/'%0D'}"

echo "::set-output name=build_args::$BUILD_ARGS"
echo "::set-output name=dockerfile::$DOCKER_FILE"

- name: Prepare
id: prep
run: |
DOCKER_TAG="${{ matrix.DOCKER_TAG }}"
DOCKER_IMAGE_NAME="$DOCKER_REPO:${DOCKER_TAG%%,*}"
echo ::set-output name=image_name::${DOCKER_IMAGE_NAME}

TAGS="$DOCKER_REPO:${DOCKER_TAG//,/,$DOCKER_REPO:}"
echo ::set-output name=tags::${TAGS}

echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')

- name: Build image
uses: docker/build-push-action@v2
with:
context: .
file: ${{ steps.args.outputs.dockerfile }}
push: false
tags: ${{ steps.prep.outputs.tags }}
build-args: |
${{ steps.args.outputs.build_args }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}

- name: Test image
env:
IMAGE_NAME: ${{ steps.prep.outputs.image_name }}
run: |
if [[ -f "docker-compose.test.yml" ]]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
fi

- name: Login to DockerHub
if: github.ref == 'refs/heads/master'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB }}

- name: Push image
if: github.ref == 'refs/heads/master'
run: |
docker push $DOCKER_REPO

- name: Report Status
if: always() && github.ref == 'refs/heads/master'
uses: ravsamhq/notify-slack-action@master
with:
status: ${{ job.status }}
notify_when: 'failure'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_GDD_GENERAL_WEBHOOK }}