Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Deployments #313

Open
wants to merge 101 commits into
base: main
Choose a base branch
from
Open
Changes from 75 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
c2dd876
Initial work towards VM deployment
thaddeus Jul 13, 2024
65213d3
Update SSH docker deploy via SSH
thaddeus Jul 14, 2024
4930d4a
Change ssh agent env
thaddeus Jul 14, 2024
d5de635
Update branch deploy to use ssh+docker deployments
thaddeus Jul 14, 2024
9b5d8fb
Skip reviews for development
thaddeus Jul 14, 2024
9fb2a14
Update test workflow
thaddeus Jul 14, 2024
cf9b441
Use proper node package script for test
thaddeus Jul 14, 2024
c62c8da
Update default development port
thaddeus Jul 14, 2024
d0e3891
Update newman collection to use development port
thaddeus Jul 14, 2024
133f8e2
Use secrets environment during test job
thaddeus Jul 14, 2024
c9dcb3f
Remove old production deployment
thaddeus Jul 14, 2024
5c0eb81
Update tag format for images
thaddeus Jul 14, 2024
068b3f3
Define image tag in deploy job
thaddeus Jul 14, 2024
a25eef9
Set tag variables explicitly
thaddeus Jul 14, 2024
c2996e4
Use proper namespace for GH PR number
thaddeus Jul 14, 2024
455909d
Remove typo from docker run
thaddeus Jul 14, 2024
3d4189d
Update HTTP README
thaddeus Jul 14, 2024
e880678
Update main deploy workflow
thaddeus Jul 14, 2024
4eb29b4
Merge pull request #2 from thaddeus/ssh-deploy
thaddeus Jul 14, 2024
7458550
Add checkout to main build job
thaddeus Jul 14, 2024
1ad247d
Test production deployment
thaddeus Jul 14, 2024
b4fdd0d
Merge pull request #3 from thaddeus/test-deploy
thaddeus Jul 14, 2024
fe921fa
Add Sentry instrumentation
thaddeus Jul 17, 2024
c455fbd
Use variables for Sentry sample rates during deployment
thaddeus Jul 17, 2024
7fb6692
Add environment to Sentry init
thaddeus Jul 17, 2024
9be813b
Use sha for Sentry release version
thaddeus Jul 17, 2024
ae46501
Update to Node 20
thaddeus Jul 17, 2024
347630a
Add explicit evironment flag
thaddeus Jul 17, 2024
ead258d
Add restart flag to docker run
thaddeus Jul 17, 2024
1924252
Add extra integration data to Sentry
thaddeus Jul 17, 2024
8cc1cd8
Manually set user
thaddeus Jul 17, 2024
eddacaa
Merge remote-tracking branch 'the-hideout/update-logging'
thaddeus Jul 18, 2024
43ec6b4
Use normal user for docker control
thaddeus Jul 18, 2024
7330155
Ignore resolve spans
thaddeus Jul 18, 2024
5cedf44
Merge branch 'main' into main
Razzmatazzz Jul 18, 2024
1f5b56c
Use cluster for serving
thaddeus Jul 19, 2024
d20a7b1
Merge remote-tracking branch 'the-hideout/graphql-yoga'
thaddeus Aug 8, 2024
9e88c24
Merge remote-tracking branch 'the-hideout/graphql-yoga'
thaddeus Aug 9, 2024
bb5ac7f
Merge pull request #6 from the-hideout/graphql-yoga
Razzmatazzz Aug 9, 2024
5933049
Merge branch 'main' into graphql-yoga
Razzmatazzz Aug 9, 2024
3cd68b6
Merge pull request #7 from the-hideout/graphql-yoga
Razzmatazzz Aug 9, 2024
d5fae03
Merge pull request #8 from the-hideout/graphql-yoga
Razzmatazzz Aug 10, 2024
39cdf89
Add cluster worker message instrumentation
thaddeus Aug 10, 2024
8ea269b
Merge pull request #9 from the-hideout/graphql-yoga
Razzmatazzz Aug 10, 2024
a12afba
Fix Sentry and add trace propagation
thaddeus Aug 10, 2024
260a1d1
Import Sentry to cache machine module
thaddeus Aug 10, 2024
5a6e07b
Use new API for trace propagation headers
thaddeus Aug 10, 2024
4277ca2
Remove broken trace propagation
thaddeus Aug 10, 2024
1624c4e
Merge pull request #10 from the-hideout/graphql-yoga
thaddeus Aug 11, 2024
0fe73a8
Revert "Don't use waitUntil"
thaddeus Aug 11, 2024
a351fca
Merge pull request #11 from thaddeus/revert-10-graphql-yoga
thaddeus Aug 11, 2024
3b53c53
Merge branch 'main' into graphql-yoga
Razzmatazzz Aug 12, 2024
ac2ad43
Merge pull request #12 from the-hideout/graphql-yoga
Razzmatazzz Aug 12, 2024
d4a4a52
Merge pull request #13 from the-hideout/graphql-yoga
Razzmatazzz Aug 14, 2024
8c17766
Merge branch 'sell-item-task' of https://github.com/the-hideout/tarko…
Razzmatazzz Aug 23, 2024
f646629
Merge pull request #15 from thaddeus/updates-from-worker
Razzmatazzz Aug 23, 2024
0094623
Merge branch 'sell-item-task' of https://github.com/the-hideout/tarko…
Razzmatazzz Aug 26, 2024
ea81a93
formatting
Razzmatazzz Aug 26, 2024
de395e9
fix package-lock
Razzmatazzz Aug 26, 2024
48de622
Merge pull request #16 from thaddeus/restart-workers
Razzmatazzz Aug 26, 2024
897b09d
Merge branch 'sell-item-task' of https://github.com/the-hideout/tarko…
Razzmatazzz Aug 27, 2024
63cbb60
Merge pull request #17 from thaddeus/pull-updates
Razzmatazzz Aug 27, 2024
60e2fda
Pull updates from worker repo
Razzmatazzz Aug 29, 2024
dc42fdc
Merge pull request #18 from thaddeus/fix-worker-messages
Razzmatazzz Aug 29, 2024
c45d271
Merge branch 'sell-item-task' of https://github.com/the-hideout/tarko…
Razzmatazzz Aug 29, 2024
50e040a
Merge pull request #19 from thaddeus/catch-worker-send-error
Razzmatazzz Aug 29, 2024
9b00189
Merge branch 'no-cache-errors' of https://github.com/the-hideout/tark…
Razzmatazzz Aug 29, 2024
5264cb8
Merge pull request #20 from thaddeus/no-cache-error
Razzmatazzz Aug 29, 2024
bf34985
Merge branch 'no-cache-errors' of https://github.com/the-hideout/tark…
Razzmatazzz Aug 30, 2024
dba36c3
Merge pull request #21 from thaddeus/fix-variable-args
Razzmatazzz Aug 30, 2024
aa4b361
Merge branch 'http-kv-queue' of https://github.com/the-hideout/tarkov…
Razzmatazzz Sep 10, 2024
3427be3
Merge pull request #22 from thaddeus/kv-request-queue
Razzmatazzz Sep 10, 2024
aae12f8
Merge pull request #23 from thaddeus/lite-api
Razzmatazzz Sep 18, 2024
d346a67
Merge pull request #24 from thaddeus/lite-api-fix
Razzmatazzz Sep 18, 2024
b80d9b4
Merge branch 'main' into endpoint-origin-passthrough
Razzmatazzz Sep 19, 2024
51fd268
Merge pull request #25 from thaddeus/endpoint-origin-passthrough
Razzmatazzz Sep 19, 2024
63e180f
Merge pull request #26 from thaddeus/upstream-pull
Razzmatazzz Sep 24, 2024
8d6f58c
Merge pull request #27 from thaddeus/artillery
Razzmatazzz Sep 26, 2024
52bef28
Merge pull request #28 from thaddeus/artillery
Razzmatazzz Sep 26, 2024
131a224
Merge pull request #29 from thaddeus/filter-historical-prices
Razzmatazzz Oct 11, 2024
f51bb27
Merge pull request #30 from thaddeus/task-available-delay
Razzmatazzz Oct 13, 2024
49b7bd5
Merge branch 'main' of https://github.com/the-hideout/tarkov-api into…
Razzmatazzz Nov 26, 2024
0a8b216
Merge pull request #32 from thaddeus/bump-branch
Razzmatazzz Nov 26, 2024
7308000
Merge branch 'item-by-normalizedname' of https://github.com/the-hideo…
Razzmatazzz Nov 29, 2024
21d1883
Merge pull request #33 from thaddeus/fix-item-by-normalizedname
Razzmatazzz Nov 29, 2024
9d84af2
Enable archived prices
Razzmatazzz Dec 16, 2024
5d2c2ed
Merge pull request #34 from thaddeus/enable-archived-prices
Razzmatazzz Dec 18, 2024
ed07a50
Merge branch 'handbook-kv' of https://github.com/the-hideout/tarkov-a…
Razzmatazzz Jan 1, 2025
ae1bad8
Merge pull request #35 from thaddeus/handbook-kv
Razzmatazzz Jan 1, 2025
a96fa11
Merge branch 'handbook-kv' of https://github.com/the-hideout/tarkov-a…
Razzmatazzz Jan 3, 2025
046da24
Merge branch 'handbook-kv' of https://github.com/the-hideout/tarkov-a…
Razzmatazzz Jan 3, 2025
84adb9e
Merge pull request #36 from thaddeus/item-properties-handbook
Razzmatazzz Jan 4, 2025
7f1b133
Merge branch 'handbook-kv' of https://github.com/the-hideout/tarkov-a…
Razzmatazzz Jan 8, 2025
f4388ea
Merge pull request #37 from thaddeus/translate-armor-slot-names
Razzmatazzz Jan 8, 2025
e7f78c1
Merge branch 'item-prices-gamemode' of https://github.com/the-hideout…
Razzmatazzz Jan 20, 2025
99a438e
Merge pull request #38 from thaddeus/item-prices-gamemode
Razzmatazzz Jan 20, 2025
08aed2f
bump dependencies
Razzmatazzz Jan 21, 2025
31ef7d6
Merge pull request #39 from thaddeus/bump-deps
Razzmatazzz Jan 21, 2025
14857a9
Add ricochet info to soft armor
Razzmatazzz Jan 31, 2025
138a9ca
Merge branch 'soft-armor-ricochet' of https://github.com/the-hideout/…
Razzmatazzz Jan 31, 2025
a6227a8
Merge pull request #40 from thaddeus/soft-armor-ricochet
Razzmatazzz Jan 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 80 additions & 24 deletions .github/workflows/branch-deploy.yml
Original file line number Diff line number Diff line change
@@ -4,12 +4,25 @@ on:
issue_comment:
types: [ created ]

# Permissions needed for reacting and adding comments for IssueOps commands

permissions:
# Permissions needed for reacting and adding comments for IssueOps commands
pull-requests: write
deployments: write
contents: write
checks: read
# Permissions needed for building and deploying docker images
packages: write
# contents: read
attestations: write
id-token: write

env:
# Environment variables used by docker build and push
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
DEFAULT_PORT: 8788
IMAGE_TAG: ghcr.io/${{ github.repository }}:pr-${{ github.event.issue.number }}

jobs:
deploy:
@@ -26,33 +39,85 @@ jobs:
environment_targets: production,development
environment_urls: production|https://api.tarkov.dev/graphql,development|https://dev-api.tarkov.dev/graphql
sticky_locks: "true"
skip_reviews: "development"

- name: checkout
if: ${{ steps.branch-deploy.outputs.continue == 'true' }}
uses: actions/checkout@v4
with:
ref: ${{ steps.branch-deploy.outputs.ref }}

- name: setup node
- name: Log in to the Container registry
if: ${{ steps.branch-deploy.outputs.continue == 'true' }}
uses: actions/setup-node@v4
uses: docker/login-action@v3.2.0
with:
node-version-file: .node-version
cache: npm
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
- name: Extract metadata (tags, labels) for Docker
if: ${{ steps.branch-deploy.outputs.continue == 'true' }}
run: npm ci
id: docker-meta
uses: docker/metadata-action@v5.5.1
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Publish - Development
if: ${{ steps.branch-deploy.outputs.environment == 'development' &&
steps.branch-deploy.outputs.noop != 'true' &&
steps.branch-deploy.outputs.continue == 'true' }}
uses: cloudflare/wrangler-action@f84a562284fc78278ff9052435d9526f9c718361 # pin@3.7.0
# In theory, we could build the container as soon as a commit is pushed, rather than waiting until just before deployment.
# This would make deployments faster, but it does mean we would have images in our repository that may not have been reviewed.
- name: Build and push Docker image to registry
if: ${{ steps.branch-deploy.outputs.continue == 'true' }}
id: docker-push
uses: docker/build-push-action@v6.3.0
with:
wranglerVersion: '2.17.0'
apiToken: ${{ secrets.CF_API_TOKEN }}
environment: "development"
context: .
push: true
tags: ${{ env.IMAGE_TAG }}
labels: ${{ steps.docker-meta.outputs.labels }}

- name: Generate artifact attestation
if: ${{ steps.branch-deploy.outputs.continue == 'true' }}
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.docker-push.outputs.digest }}
push-to-registry: true

# Setup SSH agent
- name: Setup Deployment Agent
if: ${{ steps.branch-deploy.outputs.continue == 'true' &&
steps.branch-deploy.outputs.noop != 'true' }}
id: setup-ssh
env:
# Sets up the ssh agent to be used in future steps for connecting to the deployment environment
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
# Sets the ssh host address based on the desired environment if they differ, falling back to SSH_HOST
ENV_HOST: ${{ steps.branch-deploy.outputs.environment == 'production' && secrets.SSH_HOST_PROD || secrets.SSH_HOST_DEV || secrets.SSH_HOST }}
run: |
mkdir -p /home/runner/.ssh
ssh-keyscan $ENV_HOST >> /home/runner/.ssh/known_hosts
echo "${{ secrets.SSH_PRIVATE_KEY }}" > /home/runner/.ssh/api-server-key
chmod 600 /home/runner/.ssh/api-server-key
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add /home/runner/.ssh/api-server-key
echo "ssh-host=$ENV_HOST" >> $GITHUB_OUTPUT

- name: Deploy
if: ${{ steps.branch-deploy.outputs.continue == 'true' &&
steps.branch-deploy.outputs.noop != 'true'}}
env:
# Uses the ssh agent set up in the previous step to connect to the deployment environment
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
# Allows for the API to be deployed to the same system on different ports based on the environment
ENV_PORT: ${{ steps.branch-deploy.outputs.environment == 'production' && '80' || env.DEFAULT_PORT }}
# The name of the container to be run
CONTAINER_NAME: tarkov-api-${{ steps.branch-deploy.outputs.environment }}
run: |
# Stop and remove any existing container matching our container name variable
ssh ${{ secrets.SSH_USER }}@${{ steps.setup-ssh.outputs.ssh-host }} "docker rm -f ${{ env.CONTAINER_NAME }} || true"
# Pull the latest version of the image published to the registry
ssh ${{ secrets.SSH_USER }}@${{ steps.setup-ssh.outputs.ssh-host }} "docker pull ${{ env.IMAGE_TAG }}"
# Run the image as a container
ssh ${{ secrets.SSH_USER }}@${{ steps.setup-ssh.outputs.ssh-host }} "docker run -d --name ${{ env.CONTAINER_NAME }} --restart unless-stopped -p ${{ env.ENV_PORT }}:${{ env.DEFAULT_PORT }} -e ENVIRONMENT='${{ steps.branch-deploy.outputs.environment }}' -e SENTRY_ENV='${{ steps.branch-deploy.outputs.environment }}' -e SENTRY_DSN='${{ secrets.SENTRY_DSN || '' }}' -e SENTRY_TRACE_RATE=${{ vars.SENTRY_TRACE_RATE || 0 }} -e SENTRY_PROFILE_RATE=${{ vars.SENTRY_PROFILE_RATE || 0 }} -e DEPLOY_REF='${{ github.event.pull_request.head.sha || github.sha }}' -e CLOUDFLARE_TOKEN='${{ secrets.CLOUDFLARE_TOKEN }}' -e CACHE_BASIC_AUTH='${{ secrets.CACHE_BASIC_AUTH }}' ${{ env.IMAGE_TAG }}"

# Post comment on PR with development deploy info
- uses: GrantBirki/comment@v2.1.0
@@ -71,15 +136,6 @@ jobs:

> Pusher: @${{ github.actor }}, Action: `${{ github.event_name }}`, Workflow: `${{ github.workflow }}`;

- name: Publish - Production
if: ${{ steps.branch-deploy.outputs.continue == 'true' &&
steps.branch-deploy.outputs.noop != 'true' &&
steps.branch-deploy.outputs.environment == 'production' }}
uses: cloudflare/wrangler-action@f84a562284fc78278ff9052435d9526f9c718361 # pin@3.7.0
with:
wranglerVersion: '2.17.0'
apiToken: ${{ secrets.CF_API_TOKEN }}

# Post comment on PR with production deploy info
- uses: GrantBirki/comment@v2.1.0
if: ${{ steps.branch-deploy.outputs.continue == 'true' &&
97 changes: 83 additions & 14 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -7,8 +7,57 @@ on:

permissions:
contents: read
# Permissions needed for building and deploying docker images
packages: write
# contents: read
attestations: write
id-token: write

env:
# Environment variables used by docker build and push
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
DEFAULT_PORT: 8788
IMAGE_LATEST_TAG: ghcr.io/${{ github.repository }}:latest
IMAGE_MAIN_TAG: ghcr.io/${{ github.repository }}:main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3.2.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: docker-meta
uses: docker/metadata-action@v5.5.1
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image to registry
id: docker-push
uses: docker/build-push-action@v6.3.0
with:
context: .
push: true
tags: ${{ env.IMAGE_LATEST_TAG }},${{ env.IMAGE_MAIN_TAG }}
labels: ${{ steps.docker-meta.outputs.labels }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.docker-push.outputs.digest }}
push-to-registry: true

deployment-check:
runs-on: ubuntu-latest
outputs: # set outputs for use in downstream jobs
@@ -25,25 +74,45 @@ jobs:

deploy:
if: ${{ needs.deployment-check.outputs.continue == 'true' }}
needs: deployment-check
needs:
- deployment-check
- build
environment: production
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v4

- name: setup node
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm

- name: install dependencies
run: npm ci
# Setup SSH agent
- name: Setup Deployment Agent
id: setup-ssh
env:
# Sets up the ssh agent to be used in future steps for connecting to the deployment environment
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
# Sets the ssh host address based on the desired environment if they differ, falling back to SSH_HOST
ENV_HOST: ${{ secrets.SSH_HOST_PROD || secrets.SSH_HOST }}
run: |
mkdir -p /home/runner/.ssh
ssh-keyscan $ENV_HOST >> /home/runner/.ssh/known_hosts
echo "${{ secrets.SSH_PRIVATE_KEY }}" > /home/runner/.ssh/api-server-key
chmod 600 /home/runner/.ssh/api-server-key
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add /home/runner/.ssh/api-server-key
echo "ssh-host=$ENV_HOST" >> $GITHUB_OUTPUT

- name: Publish - Production
uses: cloudflare/wrangler-action@f84a562284fc78278ff9052435d9526f9c718361 # pin@3.7.0
with:
wranglerVersion: '2.17.0'
apiToken: ${{ secrets.CF_API_TOKEN }}
- name: Deploy
env:
# Uses the ssh agent set up in the previous step to connect to the deployment environment
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
# Allows for the API to be deployed to the same system on different ports based on the environment
ENV_PORT: '80'
# The name of the container to be run
CONTAINER_NAME: tarkov-api-production
run: |
# Stop and remove any existing container matching our container name variable
ssh ${{ secrets.SSH_USER }}@${{ steps.setup-ssh.outputs.ssh-host }} "docker rm -f ${{ env.CONTAINER_NAME }} || true"
# Pull the latest version of the image published to the registry
ssh ${{ secrets.SSH_USER }}@${{ steps.setup-ssh.outputs.ssh-host }} "docker pull ${{ env.IMAGE_MAIN_TAG }}"
# Run the image as a container
ssh ${{ secrets.SSH_USER }}@${{ steps.setup-ssh.outputs.ssh-host }} "docker run -d --name ${{ env.CONTAINER_NAME }} --restart unless-stopped -p ${{ env.ENV_PORT }}:${{ env.DEFAULT_PORT }} -e ENVIRONMENT='production' -e SENTRY_ENV='production' -e SENTRY_DSN='${{ secrets.SENTRY_DSN || '' }}' -e SENTRY_TRACE_RATE=${{ vars.SENTRY_TRACE_RATE || 0 }} -e SENTRY_PROFILE_RATE=${{ vars.SENTRY_PROFILE_RATE || 0 }} -e DEPLOY_REF='${{ github.sha }}' -e CLOUDFLARE_TOKEN='${{ secrets.CLOUDFLARE_TOKEN }}' -e CACHE_BASIC_AUTH='${{ secrets.CACHE_BASIC_AUTH }}' ${{ env.IMAGE_MAIN_TAG }}"
15 changes: 10 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -12,20 +12,25 @@ permissions:

jobs:
test:
environment: secrets
runs-on: ubuntu-latest
steps:
- name: checkout
- name: Checkout
uses: actions/checkout@v4

- name: setup node
- name: Setup Node Environment
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm

- run: npm ci
- name: Install Dependencies
run: |
npm ci
cd http && npm ci

- name: test
- name: Execute Tests
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
CACHE_BASIC_AUTH: ${{ secrets.CACHE_BASIC_AUTH }}
run: script/test
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.11.0
20.15.1
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:20-slim

# Copy the files from the host to the container
COPY . /app

# Setup base package
WORKDIR /app
RUN npm ci

# Setup HTTP package
WORKDIR /app/http
RUN npm ci

ENV CLOUDFLARE_TOKEN=placeholder
ENV CACHE_BASIC_AUTH=placeholder
ENV PORT=8788
ENV ENVIRONMENT=dev
ENV SENTRY_DSN=
ENV SENTRY_TRACE_RATE=0
ENV SENTRY_PROFILE_RATE=0

EXPOSE $PORT

# Run the application
ENTRYPOINT ["npm", "run", "start"]
10 changes: 10 additions & 0 deletions docs/maintainer-notes.md
Original file line number Diff line number Diff line change
@@ -14,6 +14,16 @@ This is a simple run down of how review / deploy a pull request.

> It should be noted that the approval step can come before the deployment steps if that suits the situation better.

## Required Secrets

To deploy the API, you will need the following secrets. To deploy via GitHub Actions, you will need to add these secrets to the `secrets` and `production` environments in the repository settings.

* `CLOUDFLARE_TOKEN` - The Cloudflare API token used for accessing the KV store until such a time as we have an independent database for the new express hosted API.
* `CACHE_BASIC_AUTH` - The basic auth string to use with the cache server.
* `SSH_HOST` - The host (ip or DNS record) of the server to deploy the Docker container.
* `SSH_USER` - The user to use when connecting to the deployment server.
* `SSH_PRIVATE_KEY` - The private key to use when connecting to the deployment server.

## CI Failures

A known issue (I am not sure of the cause) for CI failures is when dependabot opens a pull request. For some very strange reason, the necessary secrets are not injected into the Actions workflow when the pull request comes from dependabot. This causes the wrangler environment in CI to fail because it lacks the proper credentials to authenticate with Cloudflare.
16 changes: 16 additions & 0 deletions http/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This folder is for running the API as a standalonen application, without using Cloudflare workers.

## Setup
1. Install [Node.js](https://nodejs.org/en/download/)
2. Run `npm install` from the parent directory to install the base dependencies
3. Run `npm install` from this directory to install the dependencies for the HTTP server

## Enviroment Variables
* `PORT` - The port the server will listen on. Default is `8088`.
* `ENVIRONMENT` - The environment to run in. Either `production` or `dev`. Default is `dev`.
* `CACHE_BASIC_AUTH` - The basic auth string to use for caching. Default is `placeholder`.
* `CLOUDFLARE_TOKEN` - The Cloudflare token to use for accessing the KV store. Default is `placeholder`.
* `SENTRY_DSN` - The Sentry DSN to use for error reporting. Defaults to empty.
* `SENTRY_TRACE_RATE` - The Sentry trace sample rate to use for error reporting. Default is `0`.
* `SENTRY_PROFILE_RATE` - The Sentry profile sample rate to use for error reporting. Default is `0`.
* `SENTRY_ENV` - The Sentry environment to use for error reporting. Default is `unknown`.
8 changes: 7 additions & 1 deletion http/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createServer } from 'node:http';
import cluster from 'node:cluster';
import { availableParallelism } from 'node:os';
import * as Sentry from "@sentry/node";
import "./instrument.mjs";
import { createServer } from 'node:http';

import 'dotenv/config';

@@ -65,6 +67,8 @@ if (cluster.isPrimary && workerCount > 0) {
};

cluster.on('message', async (worker, message) => {
// Add worker message span
const rcvWorkerMsgSpan = Sentry.startInactiveSpan({ name: "Receive worker message" });
//console.log(`message from worker ${id}:`, message);
let response = false;
if (message.action === 'getKv') {
@@ -119,6 +123,8 @@ if (cluster.isPrimary && workerCount > 0) {
}
}
}
// End the span
rcvWorkerMsgSpan.end();
});

cluster.on('exit', function (worker, code, signal) {
Loading