Skip to content

Commit

Permalink
chore(preview-envs): Add preview env workflows to camunda docs repo
Browse files Browse the repository at this point in the history
  • Loading branch information
andromaqui committed Jun 18, 2024
1 parent 369b1da commit 27b5e24
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 2 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/preview-env-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: preview-env-deploy
on:
pull_request:
types: [labeled, synchronize]

jobs:
deploy-preview:
if: github.event.pull_request.state != 'closed' && (contains( github.event.label.name, 'deploy') || contains( github.event.pull_request.labels.*.name, 'deploy'))
runs-on: ubuntu-22.04
timeout-minutes: 30
name: deploy-preview-env
steps:
- uses: actions/checkout@v2

- name: Import secrets from Vault
id: secrets
uses: hashicorp/vault-action@d1720f055e0635fd932a1d2a48f87a666a57906c
with:
url: ${{ secrets.VAULT_ADDR }}
method: approle
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}
secrets: |
secret/data/products/camunda-docs/ci/preview-environment PREVIEW_ENV_BUCKET_NAME;
secret/data/products/camunda-docs/ci/preview-environment PREVIEW_ENV_GCLOUD_SA_KEY;
- name: Install Dependencies
run: npm ci

- name: Build
env:
NODE_OPTIONS: --max_old_space_size=8192
DOCS_SITE_URL: https://${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }}
DOCS_SITE_BASE_URL: /pr-${{ github.event.number }}/
run: npm run build

- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ steps.secrets.outputs.PREVIEW_ENV_GCLOUD_SA_KEY }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2

- name: start deployment
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: "${{ github.token }}"
env: ${{ github.event.repository.name }}
ref: ${{ github.event.pull_request.head.sha }}

- name: Upload files to google bucket
env:
BUCKET_NAME: ${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }}
run: |
gcloud config set pass_credentials_to_gsutil true
gsutil -m cp -R build/* gs://$BUCKET_NAME/pr-${{ github.event.number }}
- uses: bobheadxi/deployments@v1
with:
step: finish
token: "${{ github.token }}"
status: ${{ job.status }}
env: ${{ steps.deployment.outputs.env }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}

- name: Find deployment comment
uses: peter-evans/find-comment@v1
id: find-deployment-comment
env:
BUCKET_NAME: ${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }}
with:
issue-number: ${{ github.event.number }}
body-includes: Preview environment has successfully been deployed. You can access it on https://${{ env.BUCKET_NAME }}/pr-${{ github.event.number }}/index.html.

- name: Find env tear down comment
uses: peter-evans/find-comment@v1
id: find-teardown-comment
with:
issue-number: ${{ github.event.number }}
body-includes: Your preview env has been torn down.

- name: Update env tear down comment
if: steps.find-teardown-comment.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-teardown-comment.outputs.comment-id }}
body: |
Your preview env has been torn down.
edit-mode: replace

- name: Create comment
if: steps.find-deployment-comment.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v4
env:
BUCKET_NAME: ${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }}
with:
issue-number: ${{ github.event.number }}
body: |
Preview environment has successfully been deployed. You can access it on https://${{ env.BUCKET_NAME }}/pr-${{ github.event.number }}/index.html.
edit-mode: replace
60 changes: 60 additions & 0 deletions .github/workflows/preview-env-teardown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: preview-env-teardown
on:
pull_request:
types: [unlabeled, closed]

jobs:
tear-dowm-preview-env:
if: github.event.label.name == 'deploy' || (github.event.action == 'closed' && contains( github.event.pull_request.labels.*.name, 'deploy') )
runs-on: ubuntu-22.04
timeout-minutes: 20
name: teardown-preview-env
steps:
- uses: actions/checkout@v2

- name: Import secrets
id: secrets
uses: hashicorp/vault-action@d1720f055e0635fd932a1d2a48f87a666a57906c
with:
url: ${{ secrets.VAULT_ADDR }}
method: approle
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}
secrets: |
secret/data/products/camunda-docs/ci/preview-environment PREVIEW_ENV_BUCKET_NAME;
secret/data/products/camunda-docs/ci/preview-environment PREVIEW_ENV_GCLOUD_SA_KEY;
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ steps.secrets.outputs.PREVIEW_ENV_GCLOUD_SA_KEY }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2

- name: Remove files from Google bucket
env:
BUCKET_NAME: ${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }}
run: |
gcloud config set pass_credentials_to_gsutil true
gsutil -m rm -r gs://$BUCKET_NAME/pr-${{ github.event.number }}/
- name: Find Comment
uses: peter-evans/find-comment@v1
id: find-comment
env:
BUCKET_NAME: ${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }}
with:
issue-number: ${{ github.event.number }}
body-includes: Preview environment has successfully been deployed. You can access it on https://${{ env.BUCKET_NAME }}/pr-${{ github.event.number }}/index.html.

- name: Update comment
if: steps.find-comment.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v4
env:
BUCKET_NAME: ${{ steps.secrets.outputs.PREVIEW_ENV_BUCKET_NAME }}
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
body: |
Your preview env has been torn down.
edit-mode: replace
4 changes: 2 additions & 2 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module.exports = {
title: "Camunda 8 Docs",
tagline: "Documentation for all components of Camunda 8",
// url: "https://camunda-cloud.github.io",
url: "https://docs.camunda.io",
url: process.env.DOCS_SITE_URL || "https://docs.camunda.io",
// baseUrl: "/camunda-cloud-documentation/",
baseUrl: "/",
baseUrl: process.env.DOCS_SITE_BASE_URL || "/",
customFields: {
canonicalUrlRoot: "https://docs.camunda.io",
},
Expand Down

0 comments on commit 27b5e24

Please sign in to comment.