diff --git a/.github/actions/setup-databases/action.yml b/.github/actions/setup-databases/action.yml deleted file mode 100644 index e02093e96d6..00000000000 --- a/.github/actions/setup-databases/action.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: 'Setup MongoDB and Redis' -description: 'Sets up MongoDB and Redis for testing' - -inputs: - mongodb-version: - description: 'MongoDB version to use' - required: false - default: '4.4' - redis-version: - description: 'Redis version to use' - required: false - default: '6' - -runs: - using: 'composite' - steps: - - name: Start MongoDB - uses: supercharge/mongodb-github-action@1.12.1 - with: - mongodb-version: ${{ inputs.mongodb-version }} - - - name: Start Redis - uses: supercharge/redis-github-action@1.8.0 - with: - redis-version: ${{ inputs.redis-version }} diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml index d5bc933f10f..f57ffcad4b6 100644 --- a/.github/actions/setup-node/action.yml +++ b/.github/actions/setup-node/action.yml @@ -11,30 +11,12 @@ runs: using: 'composite' steps: - name: Use Node.js ${{ inputs.node-version }} - uses: actions/setup-node@v4 + uses: actions/setup-node@v6 with: node-version: ${{ inputs.node-version }} - name: Setup pnpm - uses: pnpm/action-setup@v4.1.0 + uses: pnpm/action-setup@e94b270858c939f4f8b43f5c1438fa1d9a67ad5d # version with cache support with: - run_install: false - - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - - name: Cache pnpm modules - uses: actions/cache@v4 - env: - cache-name: cache-pnpm-modules - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ inputs.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}-${{ inputs.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }} - - - name: Install Dependencies - shell: bash - run: pnpm i + run_install: true + cache: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96c12ce30a7..eeb85e2ac55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -58,17 +58,24 @@ jobs: env: REDISMS_DISABLE_POSTINSTALL: 1 MONGOMS_DISABLE_POSTINSTALL: 1 + services: + mongodb: + image: mongo + ports: + - 27017:27017 + redis: + image: redis + ports: + - 6379:6379 steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Setup Node.js and pnpm uses: ./.github/actions/setup-node with: node-version: '22.x' - name: Build project run: npm run bundle - - name: Setup MongoDB and Redis - uses: ./.github/actions/setup-databases - name: Test Bundle Server run: bash scripts/workflow/test-server.sh @@ -76,15 +83,22 @@ jobs: name: Test timeout-minutes: 10 runs-on: ubuntu-latest + services: + mongodb: + image: mongo + ports: + - 27017:27017 + redis: + image: redis + ports: + - 6379:6379 steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Setup Node.js and pnpm uses: ./.github/actions/setup-node with: node-version: '22.x' - - name: Setup MongoDB and Redis - uses: ./.github/actions/setup-databases - name: Run Lint run: npm run lint - name: Run Tests diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0bbacb7e429..adc9d83f3f2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,56 +4,39 @@ on: - 'v*' workflow_dispatch: -name: Release (core) +name: Release + +permissions: write-all + +env: + IMAGE: innei/mx-server + REDISMS_DISABLE_POSTINSTALL: 1 + MONGOMS_DISABLE_POSTINSTALL: 1 jobs: build: - name: Main Build - runs-on: ubuntu-24.04 - env: - REDISMS_DISABLE_POSTINSTALL: 1 - MONGOMS_DISABLE_POSTINSTALL: 1 - outputs: - release_url: ${{ steps.create_release.outputs.upload_url }} + name: Core + runs-on: ubuntu-latest + services: + redis: + image: redis + ports: + - 6379:6379 + mongo: + image: mongo + ports: + - 27017:27017 steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: fetch-depth: 0 - - uses: actions/setup-node@v4 - with: - node-version: 22.x - - - name: Start MongoDB - uses: supercharge/mongodb-github-action@1.12.1 - with: - mongodb-version: 4.4 - - name: Start Redis - uses: supercharge/redis-github-action@1.8.0 - with: - redis-version: 6 - - name: Setup pnpm - uses: pnpm/action-setup@v4.1.0 - with: - run_install: false + fetch-tags: true - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - - name: Cache pnpm modules - uses: actions/cache@v4 - env: - cache-name: cache-pnpm-modules + - name: Setup Node.js and pnpm + uses: ./.github/actions/setup-node with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }} - - name: Install Dependencies - run: | - pnpm i + node-version: '22.x' - name: Build project run: | @@ -61,33 +44,145 @@ jobs: - name: Test Bundle Server run: | bash scripts/workflow/test-server.sh + - name: Zip Assets run: | sh apps/core/zip-asset.sh - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + mv release.zip release-linux.zip + + - name: Release + uses: softprops/action-gh-release@v2 with: tag_name: ${{ github.ref_name }} - release_name: ${{ github.ref_name }} - draft: false + name: ${{ github.ref_name }} prerelease: ${{ contains(fromJSON('["alpha", "beta"]'), github.ref_name) }} - - run: npx changelogithub - continue-on-error: true - env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - - name: Upload Release Asset - id: upload-release-asset - uses: actions/upload-release-asset@v1 + files: release-linux.zip + + - name: Changelog + run: npx changelogithub env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + docker: + name: Docker (${{ matrix.platform }}) + runs-on: ${{ matrix.runner }} + strategy: + matrix: + include: + - platform: linux/amd64 + runner: ubuntu-latest + - platform: linux/arm64 + runner: ubuntu-24.04-arm + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Docker Setup QEMU + uses: docker/setup-qemu-action@v3 + + - name: Metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE }} + + - name: Set up Buildx + uses: docker/setup-buildx-action@v3 + - name: Copy .env + run: | + cp .env.example .env + + - name: Build and load + uses: docker/build-push-action@v6 + with: + context: . + load: true + tags: ${{ env.IMAGE }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Test + run: | + bash ./scripts/workflow/test-docker.sh + sudo rm -rf ./data + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push by digest + id: build + uses: docker/build-push-action@v6 + with: + platforms: ${{ matrix.platform }} + context: . + tags: ${{ env.IMAGE }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,push-by-digest=true,name-canonical=true,push=true + + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + + - name: Export digest + run: | + mkdir -p ${{ runner.temp }}/digests + digest="${{ steps.build.outputs.digest }}" + touch "${{ runner.temp }}/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v6 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: ${{ runner.temp }}/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + name: Merge + runs-on: ubuntu-latest + needs: docker + steps: + - name: Download digests + uses: actions/download-artifact@v7 with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./release.zip - asset_name: release-linux.zip - asset_content_type: application/zip + path: ${{ runner.temp }}/digests + pattern: digests-* + merge-multiple: true + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + type=raw,value=latest + + - name: Create manifest list and push + working-directory: ${{ runner.temp }}/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.IMAGE }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.IMAGE }}:${{ steps.meta.outputs.version }} deploy: name: Deploy To Remote Server runs-on: ubuntu-latest @@ -128,64 +223,3 @@ jobs: cd mx ls -a node server-deploy.js --jwtSecret=$JWTSECRET --encrypt_key=$MX_ENCRYPT_KEY --encrypt_enable --scp_path=/tmp/mx-core/release-linux.zip || { echo "Deploy failed"; exit 1; } - - docker: - name: Docker Release - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] - arch: [amd64] - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Docker Setup QEMU - uses: docker/setup-qemu-action@v3.6.0 - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: | - innei/mx-server - tags: | - type=ref,event=branch - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Copy .env - run: | - cp .env.example .env - - name: Build and export to Docker - uses: docker/build-push-action@v6 - with: - context: . - load: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }},innei/mx-server:latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Test - run: | - bash ./scripts/workflow/test-docker.sh - sudo rm -rf ./data - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - id: docker_build - uses: docker/build-push-action@v6 - with: - context: . - push: true - platforms: | - linux/amd64 - linux/arm64 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/dockerfile b/dockerfile index 6cc3c83879d..e7a0536fbcf 100644 --- a/dockerfile +++ b/dockerfile @@ -1,4 +1,4 @@ -FROM node:22-alpine as builder +FROM node:22-alpine AS builder ENV MONGOMS_DISABLE_POSTINSTALL=1 ENV REDISMS_DISABLE_POSTINSTALL=1 WORKDIR /app