diff --git a/.github/workflows/dockerhub_ci.yml b/.github/workflows/dockerhub_ci.yml new file mode 100644 index 0000000..b635ed2 --- /dev/null +++ b/.github/workflows/dockerhub_ci.yml @@ -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 }}