Skip to content

Commit

Permalink
Add docker image for sidecar (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer authored Jan 10, 2024
1 parent 60b1b69 commit 4403472
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.git
.gitignore
**/*.md
dist
Dockerfile
36 changes: 33 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
name: Publish

on:
push:
branches:
- main
paths:
- '**/CHANGELOG.md'

workflow_dispatch:
inputs:
nocache:
description: 'Do not rely on existing Docker layer cache'
default: false
type: boolean
concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
publish:
name: Publish
Expand Down Expand Up @@ -41,6 +44,33 @@ jobs:
publish: pnpm changeset:publish
createGithubReleases: true

docker:
name: Docker Image
needs: publish
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Set up Docker
run: docker login --username '${{ github.actor }}' --password-stdin ghcr.io <<< "$GHCR_TOKEN"
env:
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Configure Docker Context
run: docker buildx create --driver docker-container --use

- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha,scope=prod
no-cache: ${{ inputs.nocache == 'true' }}
push: true
tags: |
ghcr.io/getsentry/spotlight:latest
ghcr.io/getsentry/spotlight:${{ github.sha }}
electron:
name: Electron Build
needs: publish
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ jobs:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}

test-docker:
name: Docker Test
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get changed files
id: changed-files-yaml
uses: tj-actions/changed-files@v41
with:
files_yaml: |
docker:
- Dockerfile
- name: Configure Docker Context
if: ${{ inputs.force || steps.changed-files-yaml.outputs.docker_any_changed == 'true' }}
run: docker buildx create --driver docker-container --use

- name: Build Docker Image
if: ${{ inputs.force || steps.changed-files-yaml.outputs.docker_any_changed == 'true' }}
uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha,scope=prod
cache-to: type=gha,mode=max,scope=prod
no-cache: ${{ inputs.nocache == 'true' }}

test-unit:
name: Unit Tests
needs: build
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:lts-bullseye-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

FROM base AS build
WORKDIR /app
COPY . /app
# https://github.com/pnpm/pnpm/issues/6295
RUN echo "dedupe-peer-dependents=false" > .npmrc
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run --filter="./packages/sidecar" build
RUN pnpm deploy --filter="./packages/sidecar" --prod /deploy/sidecar

FROM base as sidecar
# FROM gcr.io/distroless/nodejs20-debian12 as sidecar
COPY --from=build /deploy/sidecar /app
WORKDIR /app
EXPOSE 8969
ENTRYPOINT [ "./server.js" ]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"packageManager": "[email protected]",
"volta": {
"node": "18.18.0",
"node": "20.10.0",
"pnpm": "8.6.0"
}
}
2 changes: 1 addition & 1 deletion packages/sidecar/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
const { setupSidecar } = await import('./dist/main.js');
const port = process.argv[2];
const port = process.argv.length >= 3 ? Number(process.argv[2]) : undefined;
setupSidecar({ port });
4 changes: 2 additions & 2 deletions packages/sidecar/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const buffer: MessageBuffer<Payload> = new MessageBuffer<Payload>();

const isValidPort = (value: string | number) => {
if (typeof value === 'string') {
const portNumber = parseInt(value, 10);
const portNumber = Number(value);
return /^\d+$/.test(value) && portNumber > 0 && portNumber <= 65535;
}
return value > 0 && value <= 65535;
Expand All @@ -251,7 +251,7 @@ export function setupSidecar({
logger.info('Please provide a valid port.');
process.exit(1);
} else if (port) {
sidecarPort = typeof port === 'string' ? parseInt(port, 10) : port;
sidecarPort = typeof port === 'string' ? Number(port) : port;
}

if (!serverInstance) {
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4403472

Please sign in to comment.