From 2772e4f5106b365655cfb919fb6c1b5b8b461984 Mon Sep 17 00:00:00 2001 From: Grzegorz Godlewski Date: Sun, 30 Jun 2024 22:54:41 +0200 Subject: [PATCH] Fix pr nginx deploy --- .github/workflows/DevelopServerDeploy.yml | 1 + .github/workflows/feat-deploy.yml | 66 -------------- .github/workflows/pr-deploy.yml | 102 ++++++++++++++++++++++ 3 files changed, 103 insertions(+), 66 deletions(-) create mode 100644 .github/workflows/pr-deploy.yml diff --git a/.github/workflows/DevelopServerDeploy.yml b/.github/workflows/DevelopServerDeploy.yml index ea5d57b6..594882b9 100644 --- a/.github/workflows/DevelopServerDeploy.yml +++ b/.github/workflows/DevelopServerDeploy.yml @@ -72,6 +72,7 @@ jobs: run: | docker run -d --name wikigdrive-develop \ --restart unless-stopped \ + --network nginx \ -v wikiGDriveDevelop:/data \ -v /home/wikigdrive/service_account.json:/service_account.json \ -v /home/wikigdrive/env.develop:/usr/src/app/.env \ diff --git a/.github/workflows/feat-deploy.yml b/.github/workflows/feat-deploy.yml index 91c99558..34e4df1e 100644 --- a/.github/workflows/feat-deploy.yml +++ b/.github/workflows/feat-deploy.yml @@ -35,72 +35,6 @@ jobs: runs-on: wgd-dev steps: - - name: Extract branch name - shell: bash - run: echo "::set-env name=BRANCH_NAME::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" - - name: Test - run: echo "${BRANCH_NAME}" - - - uses: actions/checkout@v3 - - - name: Use Node.js 20.x - uses: actions/setup-node@v3 - with: - node-version: 20 - cache: npm - - - name: Build action runner - run: docker build -t "wgd-action-runner:${BRANCH_NAME}" --build-arg "GIT_SHA=${GITHUB_SHA}" apps/wgd-action-runner - - - name: Build hugo docs - run: | - docker run \ - -v "${GITHUB_WORKSPACE}/hugo:/site" \ - -v "${GITHUB_WORKSPACE}/website:/website" \ - -v "/var/www/${BRANCH_NAME}.wikigdrive.com:/dist/hugo" \ - --env CONFIG_TOML="/site/config/_default/config.toml" --env BASE_URL="https://${BRANCH_NAME}.wikigdrive.com" \ - wgd-action-runner:${BRANCH_NAME} /steps/step_render_hugo - - - name: Copy index for vite - run: mkdir -p ${GITHUB_WORKSPACE}/dist/hugo && cp -rf /var/www/${BRANCH_NAME}.wikigdrive.com/* ${GITHUB_WORKSPACE}/dist/hugo - - - uses: whoan/docker-build-with-cache-action@v5 - with: - image_name: "wikigdrive-feature" - image_tag: "${{ github.sha }}" - push_image_and_stages: false - build_extra_args: "{'--build-arg': 'GIT_SHA=${{ github.sha }}'}" - - - name: Stop and remove - run: docker stop "wikigdrive-${BRANCH_NAME}" ; docker rm "wikigdrive-${BRANCH_NAME}" - continue-on-error: true - - - name: "Create empty volume" - run: docker volume rm -f "wikiGDrive${BRANCH_NAME}" ; docker volume create "wikiGDrive${BRANCH_NAME}" - - - name: Start - run: | - docker run -d --name "wikigdrive-${BRANCH_NAME}" \ - --restart unless-stopped \ - --network nginx \ - -v "wikiGDrive${BRANCH_NAME}":/data \ - -v /home/wikigdrive/service_account.json:/service_account.json \ - -v /home/wikigdrive/env.develop:/usr/src/app/.env \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v "/var/www/${BRANCH_NAME}.wikigdrive.com:/usr/src/app/dist/hugo" \ - -e "GIT_SHA=${GITHUB_SHA}" \ - -e "ZIPKIN_URL=https://${BRANCH_NAME}.wikigdrive.com/zipkin" \ - -e "ZIPKIN_SERVICE=wikigdrive-${BRANCH_NAME}" \ - --link=zipkin:zipkin \ - "wikigdrive-feature:${GITHUB_SHA}" wikigdrive \ - --service_account /service_account.json \ - --share_email mie-docs-wikigdrive@wikigdrive.iam.gserviceaccount.com \ - --workdir /data \ - server 3000 - - - name: "Nginx setup" - run: "TODO" - - name: Create pull request id: open-pr uses: repo-sync/pull-request@v2 diff --git a/.github/workflows/pr-deploy.yml b/.github/workflows/pr-deploy.yml new file mode 100644 index 00000000..0e61a489 --- /dev/null +++ b/.github/workflows/pr-deploy.yml @@ -0,0 +1,102 @@ +name: Feat PR Deploy + +on: + pull_request: + branches: + types: [submitted, edited] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - run: sudo apt-get update + - run: sudo apt-get install -y libkrb5-dev + + - name: Use Node.js 20.x + uses: actions/setup-node@v3 + with: + node-version: 20 + cache: npm + + - name: Install node_modules + run: npm install + + - name: Lint + run: npm run lint + + - name: Test + run: npm run test + + build: + needs: test + runs-on: wgd-dev + + steps: + - name: Extract branch name + shell: bash + run: echo "::set-env name=BRANCH_NAME::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" + - name: Extract PR number + shell: bash + run: echo "::set-env name=PR_NUMBER::$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')" + - name: Test + run: echo "${PR_NUMBER}" + + - uses: actions/checkout@v3 + + - name: Use Node.js 20.x + uses: actions/setup-node@v3 + with: + node-version: 20 + cache: npm + + - name: Build action runner + run: docker build -t "wgd-action-runner:pr-{PR_NUMBER}" --build-arg "GIT_SHA=${GITHUB_SHA}" apps/wgd-action-runner + + - name: Build hugo docs + run: | + docker run \ + -v "${GITHUB_WORKSPACE}/hugo:/site" \ + -v "${GITHUB_WORKSPACE}/website:/website" \ + -v "/var/www/pr-{PR_NUMBER}.wikigdrive.com:/dist/hugo" \ + --env CONFIG_TOML="/site/config/_default/config.toml" --env BASE_URL="https://pr-{PR_NUMBER}.wikigdrive.com" \ + wgd-action-runner:pr-{PR_NUMBER} /steps/step_render_hugo + + - name: Copy index for vite + run: mkdir -p ${GITHUB_WORKSPACE}/dist/hugo && cp -rf /var/www/pr-{PR_NUMBER}.wikigdrive.com/* ${GITHUB_WORKSPACE}/dist/hugo + + - uses: whoan/docker-build-with-cache-action@v5 + with: + image_name: "wikigdrive-feature" + image_tag: "${{ github.sha }}" + push_image_and_stages: false + build_extra_args: "{'--build-arg': 'GIT_SHA=${{ github.sha }}'}" + + - name: Stop and remove + run: docker stop "pr-{PR_NUMBER}" ; docker rm "pr-{PR_NUMBER}" + continue-on-error: true + + - name: "Create empty volume" + run: docker volume rm -f "pr-{PR_NUMBER}" ; docker volume create "pr-{PR_NUMBER}" + + - name: Start + run: | + docker run -d --name "pr-{PR_NUMBER}" \ + --restart unless-stopped \ + --network nginx \ + -v "pr-{PR_NUMBER}":/data \ + -v /home/wikigdrive/service_account.json:/service_account.json \ + -v /home/wikigdrive/env.develop:/usr/src/app/.env \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v "/var/www/pr-{PR_NUMBER}.wikigdrive.com:/usr/src/app/dist/hugo" \ + -e "GIT_SHA=${GITHUB_SHA}" \ + -e "ZIPKIN_URL=https://pr-{PR_NUMBER}.wikigdrive.com/zipkin" \ + -e "ZIPKIN_SERVICE=pr-{PR_NUMBER}" \ + --link=zipkin:zipkin \ + "wikigdrive-feature:${GITHUB_SHA}" wikigdrive \ + --service_account /service_account.json \ + --share_email mie-docs-wikigdrive@wikigdrive.iam.gserviceaccount.com \ + --workdir /data \ + server 8080