From 5af60aa4deaf04441764990de7b97ae02eba9756 Mon Sep 17 00:00:00 2001 From: "web@ppanel" Date: Thu, 14 Nov 2024 13:35:50 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20ci(github):=20Release=20docker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release-docker.yml | 62 ++++++++++++++++++++++++++++ docker/ppanel-admin-web/Dockerfile | 9 ++-- docker/ppanel-user-web/Dockerfile | 9 ++-- 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/release-docker.yml diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml new file mode 100644 index 0000000..8e7ea0c --- /dev/null +++ b/.github/workflows/release-docker.yml @@ -0,0 +1,62 @@ +name: Build and Publish Docker Image + +on: + workflow_dispatch: + release: + types: [published] + push: + branches: + - develop + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + IMAGE_NAME: + - ppanel-user-web + - ppanel-admin-web + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract version from package.json + id: version + run: echo "VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV + + - name: Get short SHA + id: sha + run: echo "GIT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV + + - name: Build and push Docker image for main release + if: github.event_name == 'release' + uses: docker/build-push-action@v4 + with: + context: . + file: ./docker/${{ matrix.IMAGE_NAME }}/Dockerfile + push: true + tags: | + ${{ secrets.DOCKER_USERNAME }}/${{ matrix.IMAGE_NAME }}:latest + ${{ secrets.DOCKER_USERNAME }}/${{ matrix.IMAGE_NAME }}:${{ env.VERSION }} + + - name: Build and push Docker image for develop + if: github.ref == 'refs/heads/develop' + uses: docker/build-push-action@v4 + with: + context: . + file: ./docker/${{ matrix.IMAGE_NAME }}/Dockerfile + push: true + tags: | + ${{ secrets.DOCKER_USERNAME }}/${{ matrix.IMAGE_NAME }}:beta + ${{ secrets.DOCKER_USERNAME }}/${{ matrix.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.GIT_SHA }}-beta diff --git a/docker/ppanel-admin-web/Dockerfile b/docker/ppanel-admin-web/Dockerfile index 79ac514..c29bab5 100644 --- a/docker/ppanel-admin-web/Dockerfile +++ b/docker/ppanel-admin-web/Dockerfile @@ -5,8 +5,9 @@ FROM base AS builder WORKDIR /app +COPY . . + # Install dependencies based on the preferred package manager -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ # Omit --production flag for TypeScript devDependencies RUN \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ @@ -16,10 +17,8 @@ RUN \ else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ fi -COPY . . - -# Build Next.js based on the preferred package manager -RUN npx turbo build --filter=ppanel-admin-web... +RUN npx turbo telemetry disable +RUN npx turbo build --filter=ppanel-admin-web # Note: It is not necessary to add an intermediate step that does a full copy of `node_modules` here diff --git a/docker/ppanel-user-web/Dockerfile b/docker/ppanel-user-web/Dockerfile index a573823..b0f00d4 100644 --- a/docker/ppanel-user-web/Dockerfile +++ b/docker/ppanel-user-web/Dockerfile @@ -5,8 +5,9 @@ FROM base AS builder WORKDIR /app +COPY . . + # Install dependencies based on the preferred package manager -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ # Omit --production flag for TypeScript devDependencies RUN \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ @@ -16,10 +17,8 @@ RUN \ else echo "Warning: Lockfile not found. It is recommended to commit lockfiles to version control." && yarn install; \ fi -COPY . . - -# Build Next.js based on the preferred package manager -RUN npx turbo build --filter=ppanel-user-web... +RUN npx turbo telemetry disable +RUN npx turbo build --filter=ppanel-user-web # Note: It is not necessary to add an intermediate step that does a full copy of `node_modules` here