Commit 10c85c31 authored by Grant's avatar Grant
Browse files

Merge branch 'main' into dependabot-docker-node-23-alpine

parents 9ce50dd4 ea3589d4
Loading
Loading
Loading
Loading
+10 −39
Original line number Diff line number Diff line
stages:
  - publish
  - deploy

variables:
  REGISTRY: registry.sc07.dev
  IMAGE_NAME: sc07/canvas:edge

publish:
  stage: publish
  tags:
    - red
build wiki:
  stage: build
  trigger:
    include: .gitlab/ci/wiki.yml
  allow_failure: true
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
    - changes:
        - ".gitlab/*"
      when: never
    - changes:
        - "**/*.md"
      when: manual
  interruptible: true
  before_script:
    - echo $PAT | docker login $REGISTRY -u $GITLAB_USER_LOGIN --password-stdin
  script:
    - docker build . --tag $REGISTRY/$IMAGE_NAME
    - docker push $REGISTRY/$IMAGE_NAME
    - if: $CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

deploy:
  stage: deploy
  tags:
    - red
  trigger:
    include: .gitlab/ci/deploy.yml
  allow_failure: true
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
    - changes:
        - ".gitlab/*"
      when: never
    - changes:
        - "**/*.md"
      when: manual
  interruptible: true
  script:
    - cd $WORK_DIR
    - docker compose pull
    - docker compose up -d
    - if: $CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

.gitlab/ci/deploy.yml

0 → 100644
+32 −0
Original line number Diff line number Diff line
variables:
  REGISTRY: registry.sc07.dev
  IMAGE_NAME: sc07/canvas:edge

publish:
  stage: build
  tags:
    - red
  interruptible: true
  before_script:
    - echo $PAT | docker login $REGISTRY -u $GITLAB_USER_LOGIN --password-stdin
  script:
    - |
      docker build --tag $REGISTRY/$IMAGE_NAME \
      --build-arg SENTRY_URL=$SENTRY_URL \
      --build-arg SENTRY_ORG=$SENTRY_ORG \
      --build-arg CLIENT_SENTRY_PROJECT=$CLIENT_SENTRY_PROJECT \
      --build-arg CLIENT_SENTRY_DSN=$CLIENT_SENTRY_DSN \
      --build-arg SERVER_SENTRY_PROJECT=$SERVER_SENTRY_PROJECT \
      --build-arg SERVER_SENTRY_DSN=$SERVER_SENTRY_DSN \
      --build-arg SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN .
    - docker push $REGISTRY/$IMAGE_NAME

deploy:
  stage: deploy
  tags:
    - red
  interruptible: true
  script:
    - cd $WORK_DIR
    - docker compose pull
    - docker compose up -d

.gitlab/ci/wiki.yml

0 → 100644
+16 −0
Original line number Diff line number Diff line
# sync /doc/ to internal wiki repo for UI access
# see #151
build-wiki:
  image: alpine
  stage: build
  before_script:
    - apk add --no-cache git git-subtree
  script:
    - git config user.email "ci@sc07.company"
    - git config user.name "ci"
    - git remote remove gitlab-wiki || true
    - git remote add gitlab-wiki "https://ci:$CI_TOKEN@sc07.dev/sc07/canvas.wiki.git"
    - git status
    - git checkout main
    - git pull
    - git push gitlab-wiki `git subtree split -P doc main`:main --force
+16 −1
Original line number Diff line number Diff line
@@ -40,6 +40,17 @@ FROM base as build
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app

# CLIENT_SENTRY_DSN will be baked into the client package
# SERVER_SENTRY_DSN is NOT baked in and must also be supplied to image on start
# SENTRY_{URL,ORG,PROJECT,AUTH_TOKEN} are used for sourcemap pushing
ARG CLIENT_SENTRY_DSN
ARG CLIENT_SENTRY_PROJECT
ARG SERVER_SENTRY_DSN
ARG SERVER_SENTRY_PROJECT
ARG SENTRY_URL
ARG SENTRY_ORG
ARG SENTRY_AUTH_TOKEN

COPY --from=dev_dep --chown=node:node /home/node/app/ ./
COPY --chown=node:node . .

@@ -52,7 +63,8 @@ RUN sed -i -e 's/"main": ".*"/"main": ".\/dist\/index.js"/' packages/lib/package
# --- build main client ---

ARG VITE_INCLUDE_EVENT_INFO
ARG VITE_BUGSNAG_KEY
ARG SENTRY_DSN=$CLIENT_SENTRY_DSN
ARG SENTRY_PROJECT=$CLIENT_SENTRY_PROJECT
RUN npm -w packages/client run build

# --- build admin ---
@@ -63,7 +75,10 @@ RUN npm -w packages/admin run build
# --- build server ---

RUN npx -w packages/server prisma generate
ARG SENTRY_DSN=$SERVER_SENTRY_DSN
ARG SENTRY_PROJECT=$SERVER_SENTRY_PROJECT
RUN npm -w packages/server run build
RUN if [ -n "$SENTRY_AUTH_TOKEN" ]; then npm -w packages/server run sentry; fi

#
# === RUNNER ===

doc/deploy/sentry.md

0 → 100644
+56 −0
Original line number Diff line number Diff line
---
title: Sentry
---

The frontend & backend are both equiped with [Sentry](https://sentry.io) error reporting to aid with debugging.
You can selfhost Sentry [using this guide](https://develop.sentry.dev/self-hosted/).

**Note:** if the Sentry DSN environment variable isn't present, Sentry will not be initialized and therefore will not send any information

**Note:** if the PROJECT, ORG, URL, AUTH_TOKEN is not provided sourcemaps will not be uploaded at build time

**Environment Variable Keys:**

- `build` used during the build phase (usually `npm run build`)
- `dev` used during development (usually `npm run dev`)
- `runtime` used during runtime/deployment

# Docker Building

Docker builds will take the build environment variables as `--build-arg`s, with a couple changes

- Frontend's `SENTRY_DSN` & `SENTRY_PROJECT` are renamed to `CLIENT_SENTRY_DSN` & `CLIENT_SENTRY_PROJECT` respectfully
- Backend's `SENTRY_DSN` & `SENTRY_PROJECT` are renamed to `SERVER_SENTRY_DSN` & `SERVER_SENTRY_PROJECT` respectfully

As each project has to be separated within Sentry, the DSN & project IDs will be different

_See `/Dockerfile` for how they're used_<br />
_See `/.gitlab/ci/deploy.yml` for an example of a `docker build` with the arguments_

# Frontend

With how Vite builds, the environment variables will be used during the build stage to generate the client

## Environment

| Environment         | Uses       | Description                                                                                    |
| ------------------- | ---------- | ---------------------------------------------------------------------------------------------- |
| `SENTRY_DSN`        | build, dev | Frontend DSN, baked into the client as `__SENTRY_DSN__` (see `packages/client/vite.config.js`) |
| `SENTRY_PROJECT`    | build      | Project ID, used to send sourcemaps to Sentry                                                  |
| `SENTRY_ORG`        | build      | Project organization ID, used to send sourcemaps                                               |
| `SENTRY_URL`        | build      | Sentry hostname (eg `https://sentry.io`)                                                       |
| `SENTRY_AUTH_TOKEN` | build      | Auth token for sending the sourcemaps                                                          |

# Backend

## Environment

| Environment                 | Uses                | Description                                                     |
| --------------------------- | ------------------- | --------------------------------------------------------------- |
| `SENTRY_DSN`                | build, runtime, dev | Backend DSN                                                     |
| `SENTRY_TUNNEL_PROJECT_IDS` | runtime, dev        | Comma-separated list of project IDs to allow through the tunnel |
| `SENTRY_PROJECT`            | build               | Project ID, used to send sourcemaps                             |
| `SENTRY_ORG`                | build               | Project organization ID, used to send sourcemaps                |
| `SENTRY_URL`                | build               | Sentry hostname (eg `https://sentry.io`)                        |
| `SENTRY_AUTH_TOKEN`         | build               | Auth token for sending sourcemaps                               |
| `SENTRY_ENVIRONMENT`        | runtime             | Passed to Sentry to log what environment we're running in       |
Loading