From 9b8e51ec6ec9cc09fff5a24cc33c3b992c02694d Mon Sep 17 00:00:00 2001 From: YIN JIA YI Date: Mon, 11 Sep 2023 00:54:10 +0800 Subject: [PATCH 1/2] feat(ci): add global container registry (#1) * feat(ci): add global container registry --- .github/workflows/container.yml | 90 +++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 4 deletions(-) diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 5080e9b..6cea02b 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -23,13 +23,20 @@ on: env: REGISTRY: ghcr.io - EULIX_REGISTRY: ${{ secrets.EULIX_REGISTRY }} + EULIX_REGISTRY: hub.eulix.xyz + HUAWEICLOUD_REGISTRY_SH: swr.cn-east-3.myhuaweicloud.com + HUAWEICLOUD_REGISTRY_BJ: swr.cn-north-4.myhuaweicloud.com + HUAWEICLOUD_REGISTRY_GZ: swr.cn-south-1.myhuaweicloud.com + HUAWEICLOUD_REGISTRY_HK: swr.ap-southeast-1.myhuaweicloud.com + HUAWEICLOUD_REGISTRY_SG: swr.ap-southeast-3.myhuaweicloud.com + HUAWEICLOUD_REGISTRY_AF: swr.af-south-1.myhuaweicloud.com + HUAWEICLOUD_REGISTRY_LA: swr.la-north-2.myhuaweicloud.com IMAGE_NAME: ${{ github.repository }} jobs: build: - runs-on: [self-hosted, linux, x64] + runs-on: ubuntu-latest permissions: contents: read packages: write @@ -46,6 +53,9 @@ jobs: - name: Setup Docker buildx uses: docker/setup-buildx-action@v2 + - run: echo "GITHUB_REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV + shell: bash + - name: Inspect builder run: | echo "Name: ${{ steps.buildx.outputs.name }}" @@ -70,6 +80,69 @@ jobs: username: ${{ secrets.EULIX_REGISTRY_USERNAME }} password: ${{ secrets.EULIX_REGISTRY_PASSWORD }} + - name: Log into registry Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_REGISTRY_USERNAME }} + password: ${{ secrets.DOCKER_HUB_REGISTRY_PASSWORD }} + + - name: Log into registry ${{ env.HUAWEICLOUD_REGISTRY_SH }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ${{ env.HUAWEICLOUD_REGISTRY_SH }} + username: cn-east-3@${{ secrets.HUAWEICLOUD_USERNAME }} + password: ${{ secrets.HUAWEICLOUD_PASSWORD }} + + - name: Log into registry ${{ env.HUAWEICLOUD_REGISTRY_BJ }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ${{ env.HUAWEICLOUD_REGISTRY_BJ }} + username: cn-north-4@${{ secrets.HUAWEICLOUD_USERNAME }} + password: ${{ secrets.HUAWEICLOUD_PASSWORD }} + + - name: Log into registry ${{ env.HUAWEICLOUD_REGISTRY_GZ }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ${{ env.HUAWEICLOUD_REGISTRY_GZ }} + username: cn-south-1@${{ secrets.HUAWEICLOUD_USERNAME }} + password: ${{ secrets.HUAWEICLOUD_PASSWORD }} + + - name: Log into registry ${{ env.HUAWEICLOUD_REGISTRY_SG }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ${{ env.HUAWEICLOUD_REGISTRY_SG }} + username: ap-southeast-3@${{ secrets.HUAWEICLOUD_USERNAME }} + password: ${{ secrets.HUAWEICLOUD_PASSWORD }} + + - name: Log into registry ${{ env.HUAWEICLOUD_REGISTRY_HK }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ${{ env.HUAWEICLOUD_REGISTRY_HK }} + username: ap-southeast-1@${{ secrets.HUAWEICLOUD_USERNAME }} + password: ${{ secrets.HUAWEICLOUD_PASSWORD }} + + - name: Log into registry ${{ env.HUAWEICLOUD_REGISTRY_AF }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ${{ env.HUAWEICLOUD_REGISTRY_AF }} + username: af-south-1@${{ secrets.HUAWEICLOUD_USERNAME }} + password: ${{ secrets.HUAWEICLOUD_PASSWORD }} + + - name: Log into registry ${{ env.HUAWEICLOUD_REGISTRY_LA }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ${{ env.HUAWEICLOUD_REGISTRY_LA }} + username: la-north-2@${{ secrets.HUAWEICLOUD_USERNAME }} + password: ${{ secrets.HUAWEICLOUD_PASSWORD }} + - name: Extract Docker metadata id: meta uses: docker/metadata-action@v2 @@ -77,10 +150,18 @@ jobs: images: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} ${{ env.EULIX_REGISTRY }}/${{ env.IMAGE_NAME }} + aospace/${{ env.GITHUB_REPOSITORY_NAME }} + ${{ env.HUAWEICLOUD_REGISTRY_SH }}/${{ env.IMAGE_NAME }} + ${{ env.HUAWEICLOUD_REGISTRY_BJ }}/${{ env.IMAGE_NAME }} + ${{ env.HUAWEICLOUD_REGISTRY_GZ }}/${{ env.IMAGE_NAME }} + ${{ env.HUAWEICLOUD_REGISTRY_HK }}/${{ env.IMAGE_NAME }} + ${{ env.HUAWEICLOUD_REGISTRY_SG }}/${{ env.IMAGE_NAME }} + ${{ env.HUAWEICLOUD_REGISTRY_AF }}/${{ env.IMAGE_NAME }} + ${{ env.HUAWEICLOUD_REGISTRY_LA }}/${{ env.IMAGE_NAME }} - name: Build and push Docker image id: build-and-push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4.2.1 with: context: . push: ${{ github.event_name != 'pull_request' }} @@ -90,4 +171,5 @@ jobs: platforms: linux/amd64,linux/arm64 cache-from: type=gha cache-to: type=gha,mode=max - file: Dockerfile \ No newline at end of file + file: Dockerfile + provenance: false \ No newline at end of file From bff38cf6e1f19c565bb063979d219406f83500bc Mon Sep 17 00:00:00 2001 From: YIN JIA YI Date: Wed, 13 Sep 2023 12:35:44 +0800 Subject: [PATCH 2/2] feat(dockerfile): add winodws dos2unix support (#2) --- Dockerfile | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index f750b5d..a053286 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,12 @@ FROM node:16.14.2 as builder +WORKDIR /work COPY . . + +RUN apt update && apt install dos2unix -y && apt clean all +RUN find . -type f -exec dos2unix {} \; + RUN npm install && npm run build && npm run buildsingle FROM openresty/openresty:1.21.4.1-4-bullseye-fat @@ -23,13 +28,13 @@ ENV TZ=Asia/Shanghai RUN rm -rf /etc/nginx/conf.d RUN mkdir -p /var/log/nginx/ -COPY --from=builder nginx.conf.template /nginx.conf.template -COPY --from=builder verify_access_token.lua /etc/nginx/verify_access_token.lua -COPY --from=builder cert.crt /etc/nginx/certs/cert.pem -COPY --from=builder private.key /etc/nginx/certs/cert.key +COPY --from=builder /work/nginx.conf.template /nginx.conf.template +COPY --from=builder /work/verify_access_token.lua /etc/nginx/verify_access_token.lua +COPY --from=builder /work/cert.crt /etc/nginx/certs/cert.pem +COPY --from=builder /work/private.key /etc/nginx/certs/cert.key RUN mkdir -p /opt/eulixspace-web/space/ /opt/eulixspace-web/share/ -COPY --from=builder dist /opt/eulixspace-web/space -COPY --from=builder docker-entrypoint.sh / +COPY --from=builder /work/dist /opt/eulixspace-web/space +COPY --from=builder /work/docker-entrypoint.sh / RUN chmod +x /docker-entrypoint.sh -ENTRYPOINT ["/docker-entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/docker-entrypoint.sh"]