From ced4f9978a5d9566be2cb37ace3dd1c23c795506 Mon Sep 17 00:00:00 2001 From: cooder Date: Thu, 29 Feb 2024 00:05:37 +0800 Subject: [PATCH] chore: update docker config and github action --- .github/workflows/docker-release.yml | 232 +++++++++++---------------- Dockerfile | 6 +- docker-compose.yml | 7 +- 3 files changed, 102 insertions(+), 143 deletions(-) diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index b95b8b5..580f018 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -9,164 +9,124 @@ on: - "v*.*.*" concurrency: - group: docker-release-${{ github.ref }} + group: docker-release cancel-in-progress: true jobs: - build-web-images: - runs-on: ubuntu-20.04 + check-env: + permissions: + contents: none + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + check-docker: ${{ steps.check-docker.outputs.defined }} + steps: + - id: check-docker + env: + DOCKER_HUB_NAME: ${{ secrets.DOCKER_HUB_NAME }} + if: ${{ env.DOCKER_HUB_NAME != '' }} + run: echo "defined=true" >> $GITHUB_OUTPUT + + release-images: + runs-on: ubuntu-latest + timeout-minutes: 120 + permissions: + packages: write + contents: read + id-token: write steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 1 - - name: Install Dependencies - run: | - sudo apt update && sudo apt install -y nodejs npm - - name: Set up QEMU (optional) - uses: docker/setup-qemu-action@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - with: - driver-opts: network=host - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Set DOCKER_REPO_TAGGED based on branch or tag - run: | - if [[ "${{ github.ref_name }}" == "main" ]]; then - echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/wewe-rss-web:latest" >> $GITHUB_ENV - else - echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/wewe-rss-web:${{ github.ref_name }}" >> $GITHUB_ENV - fi - - name: Build and publish image for main branch or tag push event - env: - DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }} - run: | - docker buildx build \ - --build-arg name=app \ - --platform linux/amd64,linux/arm64 \ - --label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/wewe-rss-web" \ - --label "org.opencontainers.image.description=wewe-rss web image" \ - --push \ - --target web \ - --cache-from=type=local,src=/tmp/.buildx-cache \ - --cache-to=type=local,dest=/tmp/.buildx-cache \ - -t ${DOCKER_REPO_TAGGED} \ - -f Dockerfile \ - . + uses: docker/setup-buildx-action@v3 - push-web-images-to-docker-hub: - needs: build-web-images - runs-on: ubuntu-20.04 - if: github.repository == 'cooderl/wewe-rss' - steps: - - name: Checkout code - uses: actions/checkout@v3 - name: Login to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_HUB_NAME }} password: ${{ secrets.DOCKER_HUB_PASSWORD }} - - name: Set DOCKER_REPO_TAGGED based on branch or tag - run: | - if [[ "${{ github.ref_name }}" == "main" ]]; then - echo "IMAGE_TAG=latest" >> $GITHUB_ENV - else - echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV - fi - - name: Pull image from GitHub Container Registry - run: docker pull ghcr.io/${{ github.repository_owner }}/wewe-rss-web:${{env.IMAGE_TAG}} - - name: Tag image with Docker Hub repository name and version tag - run: docker tag ghcr.io/${{ github.repository_owner }}/wewe-rss-web:${{env.IMAGE_TAG}} ${{ github.repository_owner }}/wewe-rss-web:${{env.IMAGE_TAG}} - - name: Push image to Docker Hub - run: docker push ${{ github.repository_owner }}/wewe-rss-web:${{env.IMAGE_TAG}} - build-server-images: - runs-on: ubuntu-20.04 - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - name: Install Dependencies - run: | - sudo apt update && sudo apt install -y nodejs npm - - name: Set up QEMU (optional) - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - with: - driver-opts: network=host - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Set DOCKER_REPO_TAGGED based on branch or tag - run: | - if [[ "${{ github.ref_name }}" == "main" ]]; then - echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/wewe-rss-server:latest" >> $GITHUB_ENV - else - echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/wewe-rss-server:${{ github.ref_name }}" >> $GITHUB_ENV - fi - - name: Build and publish image for main branch or tag push event - env: - DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }} - run: | - docker buildx build \ - --build-arg name=app \ - --platform linux/amd64,linux/arm64 \ - --label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/wewe-rss-server" \ - --label "org.opencontainers.image.description=wewe-rss server image" \ - --push \ - --target server \ - --cache-from=type=local,src=/tmp/.buildx-cache \ - --cache-to=type=local,dest=/tmp/.buildx-cache \ - -t ${DOCKER_REPO_TAGGED} \ - -f Dockerfile \ - . - push-server-images-to-docker-hub: - needs: build-server-images - runs-on: ubuntu-20.04 - if: github.repository == 'cooderl/wewe-rss' + - name: Extract Docker metadata (web) + id: meta-ordinary + uses: docker/metadata-action@v5 + with: + images: | + ${{ secrets.DOCKER_HUB_NAME }}/wewe-rss-web + ghcr.io/cooderl/wewe-rss-web + tags: | + type=raw,value=latest,enable=true + type=raw,value=${{ github.ref_name }},enable=true + flavor: latest=false + + - name: Build and push Docker image (web) + id: build-and-push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta-ordinary.outputs.tags }} + labels: ${{ steps.meta-ordinary.outputs.labels }} + target: web + platforms: linux/amd64,linux/arm/v7,linux/arm64 + cache-from: type=gha,scope=docker-release + cache-to: type=gha,mode=max,scope=docker-release + + - name: Extract Docker metadata (server) + id: meta-ordinary + uses: docker/metadata-action@v5 + with: + images: | + ${{ secrets.DOCKER_HUB_NAME }}/wewe-rss-server + ghcr.io/cooderl/wewe-rss-server + tags: | + type=raw,value=latest,enable=true + type=raw,value=${{ github.ref_name }},enable=true + flavor: latest=false + + - name: Build and push Docker image (server) + id: build-and-push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta-ordinary.outputs.tags }} + labels: ${{ steps.meta-ordinary.outputs.labels }} + target: server + platforms: linux/amd64,linux/arm/v7,linux/arm64 + cache-from: type=gha,scope=docker-release + cache-to: type=gha,mode=max,scope=docker-release + + description: + runs-on: ubuntu-latest + needs: check-env + if: needs.check-env.outputs.check-docker == 'true' + timeout-minutes: 5 steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Login to Docker Hub - uses: docker/login-action@v2 + - uses: actions/checkout@v4 + + - name: Docker Hub Description(web) + uses: peter-evans/dockerhub-description@v4 + with: + username: ${{ secrets.DOCKER_HUB_NAME }} + password: ${{ secrets.DOCKER_HUB_PASSWORD }} + repository: ${{ secrets.DOCKER_HUB_NAME }}/wewe-rss-web + + - name: Docker Hub Description(server) + uses: peter-evans/dockerhub-description@v4 with: username: ${{ secrets.DOCKER_HUB_NAME }} password: ${{ secrets.DOCKER_HUB_PASSWORD }} - - name: Set DOCKER_REPO_TAGGED based on branch or tag - run: | - if [[ "${{ github.ref_name }}" == "main" ]]; then - echo "IMAGE_TAG=latest" >> $GITHUB_ENV - else - echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV - fi - - name: Pull image from GitHub Container Registry - run: docker pull ghcr.io/${{ github.repository_owner }}/wewe-rss-server:${{env.IMAGE_TAG}} - - name: Tag image with Docker Hub repository name and version tag - run: docker tag ghcr.io/${{ github.repository_owner }}/wewe-rss-server:${{env.IMAGE_TAG}} ${{ github.repository_owner }}/wewe-rss-server:${{env.IMAGE_TAG}} - - name: Push image to Docker Hub - run: docker push ${{ github.repository_owner }}/wewe-rss-server:${{env.IMAGE_TAG}} + repository: ${{ secrets.DOCKER_HUB_NAME }}/wewe-rss-server diff --git a/Dockerfile b/Dockerfile index a1c496f..f9730ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,9 +31,7 @@ ENV NODE_ENV=production ENV NEXT_PUBLIC_SERVER_ORIGIN_URL="http://localhost:4000" ENV NEXT_PUBLIC_ENV=prod -CMD [ "npm", "run", "start" ] - - +CMD ["npm", "run", "start"] FROM base AS server @@ -50,4 +48,4 @@ ENV MAX_REQUEST_PER_MINUTE=60 ENV AUTH_CODE="" ENV DATABASE_URL="" -CMD [ "npm", "run", "start:migrate:prod" ] +CMD ["npm", "run", "start:migrate:prod"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a76d1a8..9e5115f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,17 +5,18 @@ services: image: mysql:latest command: --default-authentication-plugin=mysql_native_password environment: + # 请修改为自己的密码 MYSQL_ROOT_PASSWORD: 123456 TZ: 'Asia/Shanghai' ports: - 3306:3306 server: - image: cooderl/wewe-rss-server + image: cooderl/wewe-rss-server:latest ports: - 4000:4000 depends_on: - - mysql + - db environment: # 数据库连接地址 - DATABASE_URL="mysql://root:123456@db:3306/wewe-rss" @@ -27,7 +28,7 @@ services: - SERVER_ORIGIN_URL=http://localhost:4000 web: - image: cooderl/wewe-rss-web + image: cooderl/wewe-rss-web:latest ports: - 3000:3000 environment: