From a59841ac7d66ac0d73f1ca2ae6e2d45ebd97c8e6 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Tue, 1 Aug 2023 18:41:31 -0300 Subject: [PATCH] ci: Isolate Docker build into steps (#29941) Co-authored-by: Diego Sampaio --- .github/actions/setup-node/action.yml | 23 ++++--- .github/workflows/ci-test-e2e.yml | 59 ++---------------- .github/workflows/ci.yml | 90 +++++++++++++++++++++++++-- apps/meteor/.mocharc.api.js | 2 +- 4 files changed, 102 insertions(+), 72 deletions(-) diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml index 47da65a5714..6fd2c291b75 100644 --- a/.github/actions/setup-node/action.yml +++ b/.github/actions/setup-node/action.yml @@ -19,15 +19,15 @@ runs: using: composite steps: - # - name: Cache Node Modules - # if: inputs.cache-modules - # id: cache-node-modules - # uses: actions/cache@v3 - # with: - # path: | - # node_modules - # **/node_modules - # key: node-modules-${{ hashFiles('yarn.lock') }} + - name: Cache Node Modules + if: inputs.cache-modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: | + node_modules + apps/meteor/node_modules + key: node-modules-${{ hashFiles('yarn.lock') }} # # Could use this command to list all paths to save: # find . -name 'node_modules' -prune | grep -v "/\.meteor/" | grep -v "/meteor/packages/" @@ -37,10 +37,9 @@ runs: uses: actions/setup-node@v3 with: node-version: ${{ inputs.node-version }} - cache: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' && 'yarn' || '' }} + cache: 'yarn' - name: yarn install - # if: inputs.install && steps.cache-node-modules.outputs.cache-hit != 'true' - if: inputs.install + if: steps.cache-node-modules.outputs.cache-hit != 'true' shell: bash run: yarn diff --git a/.github/workflows/ci-test-e2e.yml b/.github/workflows/ci-test-e2e.yml index 70ecdb179e1..960ecf015fa 100644 --- a/.github/workflows/ci-test-e2e.yml +++ b/.github/workflows/ci-test-e2e.yml @@ -35,9 +35,6 @@ on: release: required: true type: string - publish-container: - default: false - type: boolean shard: default: '[1]' required: false @@ -118,68 +115,24 @@ jobs: exit 1 fi - - name: yarn build - run: yarn build + - run: yarn build - - name: Restore build - uses: actions/download-artifact@v3 - with: - name: build - path: /tmp/build - - - name: Unpack build - run: | - cd /tmp/build - tar xzf Rocket.Chat.tar.gz - rm Rocket.Chat.tar.gz - - - name: Start containers + - name: Start containers for CE if: inputs.release == 'ce' env: MONGO_URL: 'mongodb://host.docker.internal:27017/rocketchat?replicaSet=rs0&directConnection=true' run: | - docker compose -f docker-compose-ci.yml up -d --build rocketchat + # when we are testing CE, we only need to start the rocketchat container + docker compose -f docker-compose-ci.yml up -d rocketchat - - name: Start containers + - name: Start containers for EE if: inputs.release == 'ee' env: MONGO_URL: 'mongodb://host.docker.internal:27017/rocketchat?replicaSet=rs0&directConnection=true' ENTERPRISE_LICENSE: ${{ inputs.enterprise-license }} TRANSPORTER: ${{ inputs.transporter }} run: | - docker compose -f docker-compose-ci.yml up -d --build - - - name: Login to GitHub Container Registry - if: inputs.publish-container == true && (github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'release' || github.ref == 'refs/heads/develop') - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ secrets.CR_USER }} - password: ${{ secrets.CR_PAT }} - - - name: Publish Docker images to GitHub Container Registry - if: inputs.publish-container == true && inputs.release == 'ce' && (github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'release' || github.ref == 'refs/heads/develop') - run: | - docker compose -f docker-compose-ci.yml push rocketchat - - if [[ '${{ matrix.mongodb-version }}' = '4.4' ]]; then - IMAGE_NAME_BASE="ghcr.io/${LOWERCASE_REPOSITORY}/rocket.chat:${{ inputs.gh-docker-tag }}" - - echo "Push Docker image: ${IMAGE_NAME_BASE}" - - docker tag ${IMAGE_NAME_BASE}.official $IMAGE_NAME_BASE - docker push $IMAGE_NAME_BASE - fi; - - - name: Publish Docker images (services) to GitHub Container Registry - if: inputs.publish-container == true && inputs.release == 'ee' && (github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'release' || github.ref == 'refs/heads/develop') - run: | - docker compose -f docker-compose-ci.yml push \ - authorization-service \ - account-service \ - ddp-streamer-service \ - presence-service \ - stream-hub-service + docker compose -f docker-compose-ci.yml up -d - name: Cache Playwright binaries if: inputs.type == 'ui' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a1b3eef273..738c9d9fcbc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -243,6 +243,86 @@ jobs: name: build path: /tmp/Rocket.Chat.tar.gz + build-gh-docker: + name: 🚢 Build Docker Images for Testing + needs: [build, release-versions] + if: (github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'release' || github.ref == 'refs/heads/develop') + runs-on: ubuntu-20.04 + + env: + RC_DOCKERFILE: ${{ matrix.platform == 'alpine' && needs.release-versions.outputs.rc-dockerfile-alpine || needs.release-versions.outputs.rc-dockerfile }} + RC_DOCKER_TAG: ${{ matrix.platform == 'alpine' && needs.release-versions.outputs.rc-docker-tag-alpine || needs.release-versions.outputs.rc-docker-tag }} + DOCKER_TAG: ${{ needs.release-versions.outputs.gh-docker-tag }} + LOWERCASE_REPOSITORY: ${{ needs.release-versions.outputs.lowercase-repo }} + SERVICES_PUBLISH: 'authorization-service account-service ddp-streamer-service presence-service stream-hub-service' + + strategy: + fail-fast: false + matrix: + platform: ['official', 'alpine'] + + steps: + - uses: actions/checkout@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ secrets.CR_USER }} + password: ${{ secrets.CR_PAT }} + + - name: Restore build + uses: actions/download-artifact@v3 + with: + name: build + path: /tmp/build + + - name: Unpack build + run: | + cd /tmp/build + tar xzf Rocket.Chat.tar.gz + rm Rocket.Chat.tar.gz + + - uses: dtinth/setup-github-actions-caching-for-turbo@v1 + + - name: Setup NodeJS + uses: ./.github/actions/setup-node + with: + node-version: ${{ needs.release-versions.outputs.node-version }} + cache-modules: true + install: true + + - run: yarn build + + - name: Build Docker images + run: | + args=(rocketchat) + + if [[ '${{ matrix.platform }}' = 'alpine' ]]; then + args+=($SERVICES_PUBLISH) + fi; + + docker compose -f docker-compose-ci.yml build "${args[@]}" + + - name: Publish Docker images to GitHub Container Registry + run: | + args=(rocketchat) + + if [[ '${{ matrix.platform }}' = 'alpine' ]]; then + args+=($SERVICES_PUBLISH) + fi; + + docker compose -f docker-compose-ci.yml push "${args[@]}" + + - name: Rename official Docker tag to GitHub Container Registry + if: matrix.platform == 'official' + run: | + IMAGE_NAME_BASE="ghcr.io/${LOWERCASE_REPOSITORY}/rocket.chat:${DOCKER_TAG}" + + echo "Push Docker image: ${IMAGE_NAME_BASE}" + docker tag ${IMAGE_NAME_BASE}.official $IMAGE_NAME_BASE + docker push $IMAGE_NAME_BASE + checks: needs: [release-versions, packages-build] @@ -261,13 +341,12 @@ jobs: test-api: name: 🔨 Test API (CE) - needs: [checks, build, release-versions] + needs: [checks, build-gh-docker, release-versions] uses: ./.github/workflows/ci-test-e2e.yml with: type: api release: ce - publish-container: true node-version: ${{ needs.release-versions.outputs.node-version }} lowercase-repo: ${{ needs.release-versions.outputs.lowercase-repo }} rc-dockerfile: ${{ needs.release-versions.outputs.rc-dockerfile }} @@ -281,7 +360,7 @@ jobs: test-ui: name: 🔨 Test UI (CE) - needs: [checks, build, release-versions] + needs: [checks, build-gh-docker, release-versions] uses: ./.github/workflows/ci-test-e2e.yml with: @@ -307,7 +386,7 @@ jobs: test-api-ee: name: 🔨 Test API (EE) - needs: [checks, build, release-versions] + needs: [checks, build-gh-docker, release-versions] uses: ./.github/workflows/ci-test-e2e.yml with: @@ -315,7 +394,6 @@ jobs: release: ee transporter: 'nats://nats:4222' enterprise-license: ${{ needs.release-versions.outputs.enterprise-license }} - publish-container: true mongodb-version: "['4.4']" node-version: ${{ needs.release-versions.outputs.node-version }} lowercase-repo: ${{ needs.release-versions.outputs.lowercase-repo }} @@ -330,7 +408,7 @@ jobs: test-ui-ee: name: 🔨 Test UI (EE) - needs: [checks, build, release-versions] + needs: [checks, build-gh-docker, release-versions] uses: ./.github/workflows/ci-test-e2e.yml with: diff --git a/apps/meteor/.mocharc.api.js b/apps/meteor/.mocharc.api.js index 92168e92cc9..eca1284e62e 100644 --- a/apps/meteor/.mocharc.api.js +++ b/apps/meteor/.mocharc.api.js @@ -9,5 +9,5 @@ module.exports = { timeout: 10000, bail: true, file: 'tests/end-to-end/teardown.js', - spec: ['tests/unit/app/api/server/v1/**/*.spec.*', 'tests/end-to-end/api/**/*', 'tests/end-to-end/apps/*'], + spec: ['tests/end-to-end/api/**/*', 'tests/end-to-end/apps/*'], };