diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index a54c17a..dcc7d77 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -15,39 +15,41 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@main + uses: actions/checkout@v2 with: token: ${{ secrets.PIPELINE_TOKEN }} submodules: true - # Create an array of version to push to the Dockerhub registry + - name: Prepare id: prep run: | - TAG=$(echo $(git describe ${{ github.sha }} --tags)) ## Get the tags from the SHA hash - VALID_TAG="^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" ## Will match Tags in the following format v123.231.123 or v1.2.3 will discard the following format v1.2.4- + TAG=$(echo $(git describe ${{ github.sha }} --tags)) + VALID_TAG="^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" DOCKER_IMAGE=chatbotbp/botpress_brasil_participativo VERSION=() TAGS=() if [[ $TAG =~ $VALID_TAG ]]; then - VERSION+=($(echo ${TAG} | sed -r 's/v//')) # transform v12.23.0 to 12.23.0 + VERSION+=($(echo ${TAG} | sed -r 's/v//')) VERSION+=('latest') - VERSION+=($(echo ${TAG} | sed -r 's/\./_/g')) # Transform v12.13.0 to v12_13_0 ## Added backward compatibility - echo ::set-output name=release::"true" + VERSION+=($(echo ${TAG} | sed -r 's/\./_/g')) TAGS+=("${VERSION[@]/#/${DOCKER_IMAGE}:}") + echo "release=true" >> $GITHUB_ENV elif [[ $GITHUB_REF == refs/heads/* ]]; then - VERSION+=($(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')) # transform feature/00-feature-branch to feature-00-feature-branch + VERSION+=($(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')) fi GITHUB_REGISTRY="ghcr.io/residenciaticbrisa/t2g2-chatbot-botpress" TAGS+=("${VERSION[@]/#/${GITHUB_REGISTRY}:}") IFS=, - echo ::set-output name=version::${VERSION[*]} - echo ::set-output name=tags::"${TAGS[*]}" - echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + echo "version=${VERSION[*]}" >> $GITHUB_ENV + echo "tags=${TAGS[*]}" >> $GITHUB_ENV + echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + - name: Setup Node.js uses: actions/setup-node@v2 with: node-version-file: '.nvmrc' cache: 'yarn' + - name: Build run: | export npm_config_target_platform=linux @@ -57,25 +59,28 @@ jobs: yarn run build --linux --prod --verbose yarn run package --linux cp build/docker/Dockerfile packages/bp/binaries/ + - name: DockerHub Authentication + if: env.release == 'true' uses: docker/login-action@v1 - if: ${{ steps.prep.outputs.release }} with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Login to GitHub Container Registry uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.PIPELINE_TOKEN }} + - name: Build and push uses: docker/build-push-action@v2 with: context: ./packages/bp/binaries push: true - tags: ${{ steps.prep.outputs.tags }} + tags: ${{ env.tags }} labels: | org.opencontainers.image.source=${{ github.event.repository.html_url }} - org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.created=${{ env.created }} org.opencontainers.image.revision=${{ github.sha }}