From 1e797942e9d6e71fade1fdf77f803baef6f0db49 Mon Sep 17 00:00:00 2001 From: Nguyen Thai <39090621+tk-nguyen@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:53:33 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Refactored=20build=20and=20publi?= =?UTF-8?q?sh=20workflow=20(#435)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend.yml | 44 ----- .github/workflows/build.yml | 157 ++++++++++++++++++ .github/workflows/docker.yml | 4 +- .github/workflows/documentation.yml | 4 +- .github/workflows/labels.yml | 12 +- .github/workflows/ldap-sync.yml | 15 -- .github/workflows/nextcloud-migration.yml | 15 -- .github/workflows/publish-backend.yml | 56 ------- .github/workflows/publish-frontend.yml | 83 --------- .github/workflows/publish-ldap-sync.yml | 32 ---- .../workflows/publish-nextcloud-migration.yml | 43 ----- .../publish-onlyoffice-connector.yml | 54 ------ .github/workflows/publish.yml | 87 ++++++++++ docker-bake.hcl | 56 +++++++ 14 files changed, 310 insertions(+), 352 deletions(-) delete mode 100644 .github/workflows/backend.yml create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/ldap-sync.yml delete mode 100644 .github/workflows/nextcloud-migration.yml delete mode 100644 .github/workflows/publish-backend.yml delete mode 100644 .github/workflows/publish-frontend.yml delete mode 100644 .github/workflows/publish-ldap-sync.yml delete mode 100644 .github/workflows/publish-nextcloud-migration.yml delete mode 100644 .github/workflows/publish-onlyoffice-connector.yml create mode 100644 .github/workflows/publish.yml create mode 100644 docker-bake.hcl diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml deleted file mode 100644 index 4a2444cd7..000000000 --- a/.github/workflows/backend.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: backend-build - -on: - pull_request: - branches: [main] - paths: - - "tdrive/backend/node/**" - -jobs: - lint: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - name: Prettier code style check - run: cd tdrive && docker-compose -f docker-compose.tests.yml run -e NODE_OPTIONS=--unhandled-rejections=warn node npm run lint:prettier - - name: Lint - run: cd tdrive && docker-compose -f docker-compose.tests.yml run -e NODE_OPTIONS=--unhandled-rejections=warn node npm run lint - test: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - name: e2e-mongo-test - run: | - cd tdrive - docker-compose -f docker-compose.tests.yml run --rm -e NODE_OPTIONS=--unhandled-rejections=warn -e SEARCH_DRIVER=mongodb -e DB_DRIVER=mongodb -e PUBSUB_TYPE=local node npm run test:all - docker-compose -f docker-compose.tests.yml down - - name: e2e-opensearch-test - run: | - cd tdrive - docker-compose -f docker-compose.dev.tests.opensearch.yml up -d --force-recreate opensearch-node1 postgres node - sleep 60 - docker-compose -f docker-compose.dev.tests.opensearch.yml logs - docker-compose -f docker-compose.dev.tests.opensearch.yml run -e NODE_OPTIONS=--unhandled-rejections=warn -e SEARCH_DRIVER=opensearch -e DB_DRIVER=postgres -e PUBSUB_TYPE=local node npm run test:all - docker-compose -f docker-compose.dev.tests.opensearch.yml down - - name: e2e-cassandra-test - run: cd tdrive && docker-compose -f docker-compose.tests.yml up -d scylladb elasticsearch rabbitmq && sleep 60 && docker-compose -f docker-compose.tests.yml run -e NODE_OPTIONS=--unhandled-rejections=warn -e SEARCH_DRIVER=elasticsearch -e DB_DRIVER=cassandra node npm run test:all - - name: coverage - uses: adRise/jest-cov-reporter@main - with: - branch-coverage-report-path: ./tdrive/coverage/coverage-summary.json - base-coverage-report-path: ./tdrive/coverage/coverage-summary.json - delta: 0.3 - fullCoverageDiff: true - diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..742718d46 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,157 @@ +name: Build + +on: + pull_request: + branches: [main] + paths: + - "tdrive/backend/node/**" + - "tdrive/frontend/**" + - "tdrive/connectors/onlyoffice-connector/**" + - "tdrive/backend/utils/ldap-sync/**" + - "tdrive/backend/utils/nextcloud-migration/**" + +jobs: + setup: + name: Setup jobs + runs-on: ubuntu-latest + outputs: + changes: ${{ steps.filter.outputs.changes }} + steps: + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + backend: + - "tdrive/backend/node/**" + frontend: + - "tdrive/frontend/**" + onlyoffice-connector: + - "tdrive/connectors/onlyoffice-connector/**" + ldap-sync: + - "tdrive/backend/utils/ldap-sync/**" + nextcloud-migration: + - "tdrive/backend/utils/nextcloud-migration/**" + + lint-backend: + runs-on: ubuntu-latest + if: contains(needs.setup.outputs.changes, 'backend') + needs: + - setup + steps: + - uses: actions/checkout@v4 + - name: Prettier code style check + run: | + cd tdrive + docker-compose -f docker-compose.tests.yml run -e NODE_OPTIONS=--unhandled-rejections=warn node npm run lint:prettier + - name: Lint + run: | + cd tdrive + docker-compose -f docker-compose.tests.yml run -e NODE_OPTIONS=--unhandled-rejections=warn node npm run lint + + test-backend: + runs-on: ubuntu-latest + if: contains(needs.setup.outputs.changes, 'backend') + needs: + - setup + steps: + - uses: actions/checkout@v4 + - name: e2e-mongo-test + run: | + cd tdrive + docker-compose -f docker-compose.tests.yml run --rm -e NODE_OPTIONS=--unhandled-rejections=warn -e SEARCH_DRIVER=mongodb -e DB_DRIVER=mongodb -e PUBSUB_TYPE=local node npm run test:all + docker-compose -f docker-compose.tests.yml down + - name: e2e-opensearch-test + run: | + cd tdrive + docker-compose -f docker-compose.dev.tests.opensearch.yml up -d --force-recreate opensearch-node1 postgres node + sleep 60 + docker-compose -f docker-compose.dev.tests.opensearch.yml logs + docker-compose -f docker-compose.dev.tests.opensearch.yml run -e NODE_OPTIONS=--unhandled-rejections=warn -e SEARCH_DRIVER=opensearch -e DB_DRIVER=postgres -e PUBSUB_TYPE=local node npm run test:all + docker-compose -f docker-compose.dev.tests.opensearch.yml down + - name: e2e-cassandra-test + run: | + cd tdrive + docker-compose -f docker-compose.tests.yml up -d scylladb elasticsearch rabbitmq + sleep 60 + docker-compose -f docker-compose.tests.yml run -e NODE_OPTIONS=--unhandled-rejections=warn -e SEARCH_DRIVER=elasticsearch -e DB_DRIVER=cassandra node npm run test:all + - name: coverage + uses: adRise/jest-cov-reporter@main + with: + branch-coverage-report-path: ./tdrive/coverage/coverage-summary.json + base-coverage-report-path: ./tdrive/coverage/coverage-summary.json + delta: 0.3 + fullCoverageDiff: true + + build-frontend: + runs-on: ubuntu-latest + if: contains(needs.setup.outputs.changes, 'frontend') + needs: + - setup + env: + FRONTEND_ENV: ${{ secrets.FRONTEND_ENV }} + + strategy: + matrix: + node-version: [16.x] + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - run: cd tdrive/frontend/ && yarn install + - run: cp tdrive/frontend/src/app/environment/environment.ts.dist tdrive/frontend/src/app/environment/environment.ts + - if: ${{ env.FRONTEND_ENV }} + run: echo ${{ secrets.FRONTEND_ENV }} > tdrive/frontend/src/app/environment/environment.ts + - run: cd tdrive/frontend/ && yarn test + - run: cd tdrive/frontend/ && yarn build + - name: Upload frontend build artifact + uses: actions/upload-artifact@v4 + with: + name: frontend-build + path: tdrive/frontend/build/ + + build-onlyoffice-connector: + runs-on: ubuntu-latest + if: contains(needs.setup.outputs.changes, 'onlyoffice-connector') + needs: + - setup + strategy: + matrix: + node-version: [16.x] + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies and build + run: | + cd tdrive/connectors/onlyoffice-connector + npm i + npm run build --if-present + npm run lint + + build-ldap-sync: + runs-on: ubuntu-20.04 + if: contains(needs.setup.outputs.changes, 'ldap-sync') + needs: + - setup + steps: + - uses: actions/checkout@v4 + - name: Build ldap sync + run: cd tdrive/backend/utils/ldap-sync && npm i && npm run build + + build-nextcloud-migration: + runs-on: ubuntu-20.04 + if: contains(needs.setup.outputs.changes, 'nextcloud-migration') + needs: + - setup + steps: + - uses: actions/checkout@v4 + - name: Build Nextcloud migration + run: cd tdrive/backend/utils/nextcloud-migration && npm i && npm run build diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 93d66f050..a79f6983f 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -10,11 +10,11 @@ jobs: build-frontend: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: cd tdrive && docker build -t tdrive/tdrive-frontend -f docker/tdrive-frontend/Dockerfile . build-node: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: cd tdrive && docker build --target production -t docker-registry.linagora.com/tdrive/tdrive-node -f docker/tdrive-node/Dockerfile . diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 3beaa451a..8c0fe64cb 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -9,11 +9,11 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Use Node.js 16 - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: 16 - run: npm install -g yarn diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml index a62e4459d..d8141f1f5 100644 --- a/.github/workflows/labels.yml +++ b/.github/workflows/labels.yml @@ -28,7 +28,7 @@ jobs: if: github.event.action == 'closed' && github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions-ecosystem/action-add-labels@v1 with: labels: "staging:develop" @@ -37,7 +37,7 @@ jobs: if: github.event.label.name == 'qa:ready' && github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: ref: qa fetch-depth: 0 @@ -62,7 +62,7 @@ jobs: if: github.event.label.name == 'canary:ready' && github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: ref: canary fetch-depth: 0 @@ -86,7 +86,7 @@ jobs: if: github.event.label.name == 'priority:1' && github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: ref: qa fetch-depth: 0 @@ -97,7 +97,7 @@ jobs: git config user.email "labels-bot@github.com" git cherry-pick ${{github.event.pull_request.merge_commit_sha}} git push - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: ref: canary fetch-depth: 0 @@ -108,7 +108,7 @@ jobs: git config user.email "labels-bot@github.com" git cherry-pick ${{github.event.pull_request.merge_commit_sha}} git push - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: ref: main fetch-depth: 0 diff --git a/.github/workflows/ldap-sync.yml b/.github/workflows/ldap-sync.yml deleted file mode 100644 index 889498164..000000000 --- a/.github/workflows/ldap-sync.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: ldap-sync-build - -on: - pull_request: - branches: [main] - paths: - - "tdrive/backend/utils/ldap-sync/**" - -jobs: - ldap-sync-build: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - name: Build ldap sync - run: cd tdrive/backend/utils/ldap-sync && npm i && npm run build diff --git a/.github/workflows/nextcloud-migration.yml b/.github/workflows/nextcloud-migration.yml deleted file mode 100644 index 156eb2f1d..000000000 --- a/.github/workflows/nextcloud-migration.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: nextcloud-migration-build - -on: - pull_request: - branches: [main] - paths: - - "tdrive/backend/utils/nextcloud-migration/**" - -jobs: - ldap-sync-build: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - name: Build ldap sync - run: cd tdrive/backend/utils/nextcloud-migration && npm i && npm run build diff --git a/.github/workflows/publish-backend.yml b/.github/workflows/publish-backend.yml deleted file mode 100644 index e67669250..000000000 --- a/.github/workflows/publish-backend.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: publish-backend - -# Deploy backend only if push on "main" -on: - push: - branches: [main] - paths: - - "tdrive/docker/**" - - "tdrive/backend/**" - - ".github/workflows/**" - -jobs: - publish-node: - runs-on: ubuntu-20.04 - steps: - - name: "Setup version" - run: 'echo "DOCKERTAGVERSION=2023.Q1.1223" >> $GITHUB_ENV' - - name: Set env to develop - if: endsWith(github.ref, '/develop') - run: 'echo "DOCKERTAG=develop" >> $GITHUB_ENV; echo "DOCKERTAGVERSION=2023.Q1.1223" >> $GITHUB_ENV' - - name: Set env to develop - if: endsWith(github.ref, '/qa') - run: 'echo "DOCKERTAG=qa" >> $GITHUB_ENV; echo "DOCKERTAGVERSION=2023.Q1.1223" >> $GITHUB_ENV' - - name: Set env to develop - if: endsWith(github.ref, '/canary') - run: 'echo "DOCKERTAG=canary" >> $GITHUB_ENV; echo "DOCKERTAGVERSION=${{ env.DOCKERTAGVERSION }}-canary" >> $GITHUB_ENV' - - name: Set env to production - if: endsWith(github.ref, '/main') - run: 'echo "DOCKERTAG=latest" >> $GITHUB_ENV' - - name: "Push to the registry following labels:" - run: | - echo "${{ env.DOCKERTAG }},${{ env.DOCKERTAGVERSION }}" - - uses: actions/checkout@v2 - - name: Publish to Registry - uses: elgohr/Publish-Docker-Github-Action@v5 - with: - name: tdrive/tdrive-node - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} - workdir: tdrive - registry: docker-registry.linagora.com - context: . - target: production - buildoptions: "-t docker-registry.linagora.com/tdrive/tdrive-node -f docker/tdrive-node/Dockerfile" - tags: "${{ env.DOCKERTAG }},${{ env.DOCKERTAGVERSION }}" - - name: Publish to dockerhub - uses: elgohr/Publish-Docker-Github-Action@v5 - with: - name: twakedrive/tdrive-node - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - workdir: tdrive - context: . - target: production - buildoptions: "-t twakedrive/tdrive-node -f docker/tdrive-node/Dockerfile" - tags: "${{ env.DOCKERTAG }},${{ env.DOCKERTAGVERSION }}" diff --git a/.github/workflows/publish-frontend.yml b/.github/workflows/publish-frontend.yml deleted file mode 100644 index 76bbd6656..000000000 --- a/.github/workflows/publish-frontend.yml +++ /dev/null @@ -1,83 +0,0 @@ -name: publish-frontend - -# Edit with caution ! Made for build+test on "feature/*" push and pull requests events -# And for only deploying on pushes on "main" branch -on: - push: - branches: [main] - paths: - - "tdrive/frontend/**" - - "tdrive/docker/**" - - ".github/workflows/**" - pull_request: - branches: [main] - paths: - - "tdrive/frontend/**" - -jobs: - build-frontend: - runs-on: ubuntu-20.04 - env: - FRONTEND_ENV: ${{secrets.FRONTEND_ENV}} - - strategy: - matrix: - node-version: [16.x] - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm install -g yarn - - run: cd tdrive/frontend/ && yarn install - - run: cp tdrive/frontend/src/app/environment/environment.ts.dist tdrive/frontend/src/app/environment/environment.ts - - if: ${{env.FRONTEND_ENV}} - run: echo ${{ secrets.FRONTEND_ENV }} > tdrive/frontend/src/app/environment/environment.ts - - run: cd tdrive/frontend/ && yarn test - - run: cd tdrive/frontend/ && yarn build - - name: Upload frontend build artifact - uses: actions/upload-artifact@v1 - with: - name: frontend-build - path: tdrive/frontend/build/ - - publish-frontend: - # needs: build-frontend - runs-on: ubuntu-20.04 - if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/qa' || github.ref == 'refs/heads/canary' - steps: - - run: 'echo "DOCKERTAGVERSION=2023.Q1.1223" >> $GITHUB_ENV' - - name: Set env to develop - if: endsWith(github.ref, '/develop') - run: 'echo "DOCKERTAG=develop" >> $GITHUB_ENV; echo "DOCKERTAGVERSION=2023.Q1.1223" >> $GITHUB_ENV' - - name: Set env to develop - if: endsWith(github.ref, '/qa') - run: 'echo "DOCKERTAG=qa" >> $GITHUB_ENV; echo "DOCKERTAGVERSION=2023.Q1.1223" >> $GITHUB_ENV' - - name: Set env to develop - if: endsWith(github.ref, '/canary') - run: 'echo "DOCKERTAG=canary" >> $GITHUB_ENV; echo "DOCKERTAGVERSION=${{ env.DOCKERTAGVERSION }}-canary" >> $GITHUB_ENV' - - name: Set env to production - if: endsWith(github.ref, '/main') - run: 'echo "DOCKERTAG=latest" >> $GITHUB_ENV' - - uses: actions/checkout@v2 - - name: Publish to Registry - uses: elgohr/Publish-Docker-Github-Action@v5 - with: - name: tdrive/tdrive-frontend - registry: docker-registry.linagora.com - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} - workdir: tdrive - buildoptions: "-t docker-registry.linagora.com/tdrive/tdrive-frontend -f docker/tdrive-frontend/Dockerfile" - tags: "${{ env.DOCKERTAG }},${{ env.DOCKERTAGVERSION }}" - - name: Publish to dockerhub - uses: elgohr/Publish-Docker-Github-Action@v5 - with: - name: twakedrive/tdrive-frontend - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - workdir: tdrive - buildoptions: "-t twakedrive/tdrive-frontend -f docker/tdrive-frontend/Dockerfile" - tags: "${{ env.DOCKERTAG }},${{ env.DOCKERTAGVERSION }}" diff --git a/.github/workflows/publish-ldap-sync.yml b/.github/workflows/publish-ldap-sync.yml deleted file mode 100644 index 25990197c..000000000 --- a/.github/workflows/publish-ldap-sync.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: publish-ldap-sync - -on: - push: - branches: [main] - paths: - - "tdrive/backend/utils/ldap-sync/**" - - "tdrive/docker/**" - -jobs: - publish-node: - runs-on: ubuntu-20.04 - steps: - - name: Set env to production - if: endsWith(github.ref, '/main') - run: 'echo "DOCKERTAG=latest" >> $GITHUB_ENV' - - name: "Push to the registry following labels:" - run: | - echo "${{ env.DOCKERTAG }},${{ env.DOCKERTAGVERSION }}" - - uses: actions/checkout@v2 - - name: Publish to Registry - uses: elgohr/Publish-Docker-Github-Action@v5 - with: - name: tdrive/tdrive-ldap-sync - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} - workdir: tdrive - registry: docker-registry.linagora.com - context: . - target: production - buildoptions: "-t docker-registry.linagora.com/tdrive/tdrive-ldap-sync -f docker/tdrive-ldap-sync/Dockerfile" - tags: "${{ env.DOCKERTAG }},${{ env.DOCKERTAGVERSION }}" \ No newline at end of file diff --git a/.github/workflows/publish-nextcloud-migration.yml b/.github/workflows/publish-nextcloud-migration.yml deleted file mode 100644 index f149c6fe9..000000000 --- a/.github/workflows/publish-nextcloud-migration.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: publish-nextcloud-migration - -on: - push: - branches: [main] - paths: - - "tdrive/backend/utils/nextcloud-migration/**" - - "tdrive/docker/tdrive-nextcloud-migration/**" - -jobs: - publish-node: - runs-on: ubuntu-20.04 - steps: - - name: Set env to production - if: endsWith(github.ref, '/main') - run: 'echo "DOCKERTAG=latest" >> $GITHUB_ENV' - - name: "Push to the registry following labels:" - run: | - echo "${{ env.DOCKERTAG }},${{ env.DOCKERTAGVERSION }}" - - uses: actions/checkout@v2 - - name: Publish to Registry - uses: elgohr/Publish-Docker-Github-Action@v5 - with: - name: tdrive/tdrive-nextcloud-migration - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} - workdir: tdrive - registry: docker-registry.linagora.com - context: . - target: production - buildoptions: "-t docker-registry.linagora.com/tdrive/tdrive-nextcloud-migration -f docker/tdrive-nextcloud-migration/Dockerfile" - tags: "${{ env.DOCKERTAG }},${{ env.DOCKERTAGVERSION }}" - - name: Publish to dockerhub - uses: elgohr/Publish-Docker-Github-Action@v5 - with: - name: twakedrive/tdrive-nextcloud-migration - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - workdir: tdrive - context: . - target: production - buildoptions: "-t docker-registry.linagora.com/tdrive/tdrive-nextcloud-migration -f docker/tdrive-nextcloud-migration/Dockerfile" - tags: "${{ env.DOCKERTAG }},${{ env.DOCKERTAGVERSION }}" \ No newline at end of file diff --git a/.github/workflows/publish-onlyoffice-connector.yml b/.github/workflows/publish-onlyoffice-connector.yml deleted file mode 100644 index 4432627d1..000000000 --- a/.github/workflows/publish-onlyoffice-connector.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: publish-onlyoffice-connector - -# Deploy onlyoffice-connector only if push on "main" -on: - push: - branches: [main] - paths: - - "tdrive/docker/**" - - "tdrive/onlyoffice-connector/**" - - ".github/workflows/**" - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [16.x] - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - - - name: Install dependencies and build - run: | - npm ci - npm run build --if-present - npm run lint - working-directory: ./server - env: - CI: true - - publish: - runs-on: ubuntu-20.04 - needs: build - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Publish to Registry - uses: elgohr/Publish-Docker-Github-Action@v5 - with: - name: tdrive/onlyoffice-connector - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} - workdir: . - registry: docker-registry.linagora.com - context: . - target: production - buildoptions: "-t docker-registry.linagora.com/tdrive/onlyoffice-connector" - tags: "latest" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..779d8a0ef --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,87 @@ +name: Publish + +on: + push: + tags: + - "*.*.*" + paths: + - "tdrive/backend/node/**" + - "tdrive/frontend/**" + - "tdrive/connectors/onlyoffice-connector/**" + - "tdrive/backend/utils/ldap-sync/**" + - "tdrive/backend/utils/nextcloud-migration/**" + - "tdrive/docker/**" + +jobs: + setup: + name: Setup jobs + runs-on: ubuntu-latest + outputs: + targets: ${{ steps.filter.outputs.changes }} + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + backend: + - "tdrive/backend/node/**" + frontend: + - "tdrive/frontend/**" + onlyoffice-connector: + - "tdrive/connectors/onlyoffice-connector/**" + ldap-sync: + - "tdrive/backend/utils/ldap-sync/**" + nextcloud-migration: + - "tdrive/backend/utils/nextcloud-migration/**" + + publish: + runs-on: ubuntu-latest + strategy: + matrix: + targets: ${{ fromJSON(needs.setup.outputs.targets) }} + fail-fast: false + needs: + - setup + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Login to Linagora Registry + uses: docker/login-action@v3 + with: + registry: docker-registry.linagora.com + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build and push + uses: docker/bake-action@v4 + with: + files: | + ./docker-bake.hcl + ${{ steps.meta.outputs.bake-file-annotations }} + ${{ steps.meta.outputs.bake-file }} + push: true + targets: ${{ matrix.targets }} diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 000000000..79bc11f6f --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,56 @@ +function "generate_tags" { + params = [image, tags] + result = formatlist("%s:%s", image, tags) +} + +target "docker-metadata-action" {} + +target "_common" { + platforms = ["linux/amd64", "linux/arm64"] + context = "tdrive" + inherits = ["docker-metadata-action"] +} + +target "backend" { + inherits = ["_common"] + dockerfile = "docker/tdrive-node/Dockerfile" + target = "production" + tags = concat( + generate_tags("docker.io/linagora/tdrive-node", target.docker-metadata-action.tags), + generate_tags("docker-registry.linagora.com/tdrive/tdrive-node", target.docker-metadata-action.tags), + ) +} + +target "frontend" { + inherits = ["_common"] + dockerfile = "docker/tdrive-frontend/Dockerfile" + tags = concat( + generate_tags("docker.io/linagora/tdrive-frontend", target.docker-metadata-action.tags), + generate_tags("docker-registry.linagora.com/tdrive/tdrive-frontend", target.docker-metadata-action.tags), + ) +} + +target "onlyoffice-connector" { + inherits = ["_common"] + dockerfile = "docker/onlyoffice-connector/Dockerfile" + tags = concat( + generate_tags("docker.io/linagora/onlyoffice-connector", target.docker-metadata-action.tags), + generate_tags("docker-registry.linagora.com/tdrive/onlyoffice-connector", target.docker-metadata-action.tags), + ) +} +target "ldap-sync" { + inherits = ["_common"] + dockerfile = "docker/tdrive-ldap-sync/Dockerfile" + tags = concat( + generate_tags("docker.io/linagora/tdrive-ldap-sync", target.docker-metadata-action.tags), + generate_tags("docker-registry.linagora.com/tdrive/tdrive-ldap-sync", target.docker-metadata-action.tags), + ) +} +target "nextcloud-migration" { + inherits = ["_common"] + dockerfile = "docker/tdrive-nextcloud-migration/Dockerfile" + tags = concat( + generate_tags("docker.io/linagora/tdrive-nextcloud-migration", target.docker-metadata-action.tags), + generate_tags("docker-registry.linagora.com/tdrive/tdrive-nextcloud-migration", target.docker-metadata-action.tags), + ) +}