Skip to content
Snippets Groups Projects
docker_img.yml 9.09 KiB
Newer Older
name: '[docker image]'

on:
  push:
    # do not rebuild if...
    paths-ignore:
      # changes to .openshift directory... mostly devops config
      - '.openshift/*'
      # docs (docs are built on readthedocs any way)
      - 'docs/**/*'

jobs:
  build-docker-img:
    runs-on: ubuntu-latest
    env:
      MATOMO_ID_PROD: '12'
Xiao Gui's avatar
Xiao Gui committed
      MATOMO_URL_PROD: 'https://stats.humanbrainproject.eu/'
Xiao Gui's avatar
Xiao Gui committed
      DOCKER_REGISTRY: 'docker-registry.ebrains.eu/siibra/'
      SIIBRA_API_STABLE: 'https://siibra-api-stable.apps.hbp.eu/v3_0,https://siibra-api-stable.apps.jsc.hbp.eu/v3_0'
Xiao Gui's avatar
Xiao Gui committed
      SIIBRA_API_RC: 'https://siibra-api-rc.apps.hbp.eu/v3_0'
Xiao Gui's avatar
Xiao Gui committed
      SIIBRA_API_LATEST: 'https://siibra-api-latest.apps-dev.hbp.eu/v3_0'
      SIIBRA_API_LOCAL: 'http://localhost:10081/v3_0'
      LOCAL_TAG: 'local-10081'

    strategy:
      matrix:
        build: [ 'local', 'prod' ]
    - uses: actions/checkout@v3
    - name: 'Set matomo env var'
      # if matrix.build is local, only run if master or dev
      if: ${{ !(matrix.build == 'local' && github.ref != 'refs/heads/master' && github.ref != 'refs/heads/dev') }} 
      run: |
        echo "Using github.ref: $GITHUB_REF"

        echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
        
        echo "MATOMO_URL=${{ env.MATOMO_URL_PROD }}" >> $GITHUB_ENV
        echo "MATOMO_ID=${{ env.MATOMO_ID_PROD }}" >> $GITHUB_ENV

Xiao Gui's avatar
Xiao Gui committed
        if [[ "$GITHUB_REF" == 'refs/heads/master' ]]
Xiao Gui's avatar
Xiao Gui committed
          echo "Either master, using prod env..."
          echo "SIIBRA_API_ENDPOINTS=${{ env.SIIBRA_API_STABLE }}" >> $GITHUB_ENV
Xiao Gui's avatar
Xiao Gui committed
        elif [[ "$GITHUB_REF" == 'refs/heads/staging' ]]
        then
          echo "Either staging, using staging env..."
          echo "SIIBRA_API_ENDPOINTS=${{ env.SIIBRA_API_RC }}" >> $GITHUB_ENV
          if [[ "$GITHUB_REF" == *hotfix* ]]
          then
            echo "Hotfix branch, using prod env..."
            echo "SIIBRA_API_ENDPOINTS=${{ env.SIIBRA_API_RC }}" >> $GITHUB_ENV
          else
            echo "Using dev env..."
            echo "SIIBRA_API_ENDPOINTS=${{ env.SIIBRA_API_LATEST }}" >> $GITHUB_ENV
        
        if [[ "${{ matrix.build }}" == "local" ]]
        then
Xiao Gui's avatar
Xiao Gui committed
          echo "SIIBRA_API_ENDPOINTS=${{ env.SIIBRA_API_LOCAL }}" >> $GITHUB_ENV
          echo "MATOMO_URL=" >> $GITHUB_ENV
          echo "MATOMO_ID=" >> $GITHUB_ENV
Xiao Gui's avatar
Xiao Gui committed
        fi
Xiao Gui's avatar
Xiao Gui committed
    - name: 'Set version variable & expmt feature flag'
      # if matrix.build is local, only run if master or dev
      if: ${{ !(matrix.build == 'local' && github.ref != 'refs/heads/master' && github.ref != 'refs/heads/dev') }} 
      run: |
        if [[ "$GITHUB_REF" == 'refs/heads/master' ]] || [[ "$GITHUB_REF" == 'refs/heads/staging' ]]
        then
Xiao Gui's avatar
Xiao Gui committed
          echo "prod/staging build, do not enable experimental features"
Xiao Gui's avatar
Xiao Gui committed
          echo "dev bulid, enable experimental features"
Xiao Gui's avatar
Xiao Gui committed
          echo "EXPERIMENTAL_FEATURE_FLAG=true" >> $GITHUB_ENV
        fi
    - name: 'Build docker image'
      # if matrix.build is local, only run if master or dev
      if: ${{ !(matrix.build == 'local' && github.ref != 'refs/heads/master' && github.ref != 'refs/heads/dev') }} 
      run: |
        DOCKER_BUILT_TAG=${{ env.DOCKER_REGISTRY }}siibra-explorer:$BRANCH_NAME
        if [[ "${{ matrix.build }}" == "local" ]]
        then
          DOCKER_BUILT_TAG="$DOCKER_BUILT_TAG"-${{ env.LOCAL_TAG }}
        fi
        echo "Building $DOCKER_BUILT_TAG"
        docker build \
Xiao Gui's avatar
Xiao Gui committed
          --build-arg MATOMO_URL=$MATOMO_URL \
          --build-arg MATOMO_ID=$MATOMO_ID \
          --build-arg SIIBRA_API_ENDPOINTS=$SIIBRA_API_ENDPOINTS \
Xiao Gui's avatar
Xiao Gui committed
          --build-arg EXPERIMENTAL_FEATURE_FLAG=$EXPERIMENTAL_FEATURE_FLAG \
          -t $DOCKER_BUILT_TAG \
          .
        echo "Successfully built $DOCKER_BUILT_TAG"
        echo "DOCKER_BUILT_TAG=$DOCKER_BUILT_TAG" >> $GITHUB_ENV

    - name: 'Push to docker registry'
      # if matrix.build is local, only run if master or dev
      if: ${{ !(matrix.build == 'local' && github.ref != 'refs/heads/master' && github.ref != 'refs/heads/dev') }} 
      run: |
        echo "Login to docker registry"
        docker login \
          -u '${{ secrets.EBRAINS_DOCKER_REG_USER }}' \
          -p '${{ secrets.EBRAINS_DOCKER_REG_TOKEN }}' \
          docker-registry.ebrains.eu
        echo "Pushing $DOCKER_BUILT_TAG"
        docker push $DOCKER_BUILT_TAG
  setting-vars:
xgui3783's avatar
xgui3783 committed
    if: success()
    runs-on: ubuntu-latest
    outputs:
      BRANCH_NAME: ${{ steps.set-vars.outputs.BRANCH_NAME }}
      BUILD_TEXT: ${{ steps.set-vars.outputs.BUILD_TEXT }}
      DEPLOY_ID: ${{ steps.set-vars.outputs.DEPLOY_ID }}
xgui3783's avatar
xgui3783 committed
    steps:
      - uses: actions/checkout@v3
      - id: set-vars
        name: Set vars
xgui3783's avatar
xgui3783 committed
        run: |
          echo "Using github.ref: $GITHUB_REF"
xgui3783's avatar
xgui3783 committed
          BRANCH_NAME=${GITHUB_REF#refs/heads/}
          echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT

xgui3783's avatar
xgui3783 committed
          echo "Branch is $BRANCH_NAME ."
Xiao Gui's avatar
Xiao Gui committed

          if [[ "$BRANCH_NAME" == 'master' ]]
          then
            echo "BUILD_TEXT=" >> $GITHUB_OUTPUT
Xiao Gui's avatar
Xiao Gui committed
          else
            echo "BUILD_TEXT=$BRANCH_NAME" >> $GITHUB_OUTPUT
Xiao Gui's avatar
Xiao Gui committed
          # DEPLOY_ID == remove _ / and lowercase everything from branch
          DEPLOY_ID=$(echo ${BRANCH_NAME//[_\/]/} | awk '{ print tolower($0) }')
          echo "DEPLOY_ID=$DEPLOY_ID" >> $GITHUB_OUTPUT

  trigger-deploy-master-prod:
    if: ${{ needs.setting-vars.outputs.BRANCH_NAME == 'master' && success() }}
    needs:
      - build-docker-img
      - setting-vars
    uses: ./.github/workflows/deploy-on-okd.yml
    with:
      FULL_DEPLOY_ID: siibra-explorer-branch-deploy-2-prodpathviewer
      OKD_ENDPOINT: https://okd.hbp.eu:443
      OKD_PROJECT: interactive-viewer
    secrets:
      okd_token: ${{ secrets.OKD_PROD_SECRET }}

Xiao Gui's avatar
Xiao Gui committed
  trigger-deploy-master-rancher:
    if: ${{ needs.setting-vars.outputs.BRANCH_NAME == 'master' && success() }}
    needs:
      - build-docker-img
      - setting-vars
    uses: ./.github/workflows/deploy-helm.yml
    with:
      IMAGE_TAG: master
    secrets:
      KUBECONFIG: ${{ secrets.KUBECONFIG }}

  trigger-deploy-master-legacy:
    if: ${{ needs.setting-vars.outputs.BRANCH_NAME == 'master' && success() }}
    needs:
      - build-docker-img
      - setting-vars
    uses: ./.github/workflows/deploy-on-okd.yml
    with:
      FULL_DEPLOY_ID: siibra-explorer-branch-deploy-2-iav-legacy
      OKD_ENDPOINT: https://okd.hbp.eu:443
      OKD_PROJECT: interactive-viewer
    secrets:
      okd_token: ${{ secrets.OKD_PROD_SECRET }}
      
  trigger-deploy-staging-viewer-validation:
    if: ${{ needs.setting-vars.outputs.BRANCH_NAME == 'staging' && success() }}
    needs:
      - build-docker-img
      - setting-vars
    uses: ./.github/workflows/deploy-on-okd.yml
    with:
      FULL_DEPLOY_ID: siibra-explorer-branch-deploy-2-stagingpathed
      OKD_ENDPOINT: https://okd.hbp.eu:443
      OKD_PROJECT: interactive-viewer
    secrets:
      okd_token: ${{ secrets.OKD_PROD_SECRET }}
      
  trigger-deploy-staging-data-validation:
    if: ${{ needs.setting-vars.outputs.BRANCH_NAME == 'staging' && success() }}
    needs:
      - build-docker-img
      - setting-vars
    uses: ./.github/workflows/deploy-on-okd.yml
    with:
      FULL_DEPLOY_ID: siibra-explorer-rc
      OKD_ENDPOINT: https://okd.jsc.hbp.eu:443
      OKD_PROJECT: siibra-explorer
    secrets:
      okd_token: ${{ secrets.OKD_JSC_TOKEN }}
  
  trigger-deploy-other-viewer:
    # n.b. "env" context not available in "if" block
    if: ${{ needs.setting-vars.outputs.BRANCH_NAME != 'staging' && needs.setting-vars.outputs.BRANCH_NAME != 'master' && success() }}
    uses: ./.github/workflows/deploy-on-okd.yml
    needs:
      - build-docker-img
      - setting-vars
    with:
      FULL_DEPLOY_ID: siibra-explorer-branch-deploy-2-${{ needs.setting-vars.outputs.DEPLOY_ID }}
      OKD_ENDPOINT: https://okd-dev.hbp.eu:443
      OKD_PROJECT: interactive-atlas-viewer
      BRANCH_NAME: ${{ needs.setting-vars.outputs.BRANCH_NAME }}
      DEPLOY_ID: ${{ needs.setting-vars.outputs.DEPLOY_ID }}
      ROUTE_HOST: siibra-explorer.apps-dev.hbp.eu
      ROUTE_PATH: /${{ needs.setting-vars.outputs.DEPLOY_ID }}
      BUILD_TEXT: ${{ needs.setting-vars.outputs.BRANCH_NAME }}
    secrets:
      okd_token: ${{ secrets.OKD_DEV_SECRET }}

  trigger-deploy-other-badge:
    if: ${{ needs.setting-vars.outputs.BRANCH_NAME != 'staging' && needs.setting-vars.outputs.BRANCH_NAME != 'master' && success() }}
    runs-on: ubuntu-latest
    env:
      DEPLOY_URL: https://siibra-explorer.apps-dev.hbp.eu/${{ needs.setting-vars.outputs.DEPLOY_ID }}
Xiao Gui's avatar
Xiao Gui committed
      GITHUB_API_ROOT: https://api.github.com/repos/fzj-inm1-bda/siibra-explorer
    needs:
    - trigger-deploy-other-viewer
    - setting-vars
    steps:
    - name: "Update Badge"
      run: |
        curl -v \
          -X POST \
          -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
          -H 'accept: application/vnd.github.v3+json' \
          ${GITHUB_API_ROOT}/statuses/${GITHUB_SHA} \
          -d '{
Xiao Gui's avatar
Xiao Gui committed
            "target_url":"${{ env.DEPLOY_URL }}",
            "name": "Deployed at OKD",
            "description": "Deployed at OKD",
            "context": "[ebrains-okd-deploy] Deployed at OKD",
            "state": "success"
          }'