From 7d2a67075354a9ee8a797126e9812abccdc84426 Mon Sep 17 00:00:00 2001 From: Gabriel Zaranza <116514986+GZaranza@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:15:20 -0300 Subject: [PATCH] Create docker-push.yml --- .github/workflows/docker-push.yml | 86 +++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/docker-push.yml diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml new file mode 100644 index 0000000..dcc7d77 --- /dev/null +++ b/.github/workflows/docker-push.yml @@ -0,0 +1,86 @@ +name: Docker +on: + push: + release: + types: [published] +permissions: + contents: read + +jobs: + build_and_push_docker: + permissions: + packages: write + contents: none + name: Build and Push Docker Image + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + token: ${{ secrets.PIPELINE_TOKEN }} + submodules: true + + - name: Prepare + id: prep + run: | + 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//')) + VERSION+=('latest') + 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')) + fi + GITHUB_REGISTRY="ghcr.io/residenciaticbrisa/t2g2-chatbot-botpress" + TAGS+=("${VERSION[@]/#/${GITHUB_REGISTRY}:}") + IFS=, + 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 + export EDITION=pro + git submodule update --init + yarn --force --ignore-engines --frozen-lockfile + 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 + 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: ${{ env.tags }} + labels: | + org.opencontainers.image.source=${{ github.event.repository.html_url }} + org.opencontainers.image.created=${{ env.created }} + org.opencontainers.image.revision=${{ github.sha }}