diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..74bc3d4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +node_modules +dist +.git +.github +__tests__ +coverage +*.tsbuildinfo +.env* +.claude +foundation +CLAUDE.md +.foundation-* +vitest.config.ts diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..39d3f04 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,54 @@ +name: Build and Push Docker Image + +on: + push: + branches: [main] + tags: ['v*'] + pull_request: + branches: [main] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: jtalborough/relayplane-proxy + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha,prefix= + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1374b82 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:18-alpine AS builder +WORKDIR /app +COPY package.json package-lock.json* ./ +RUN if [ -f package-lock.json ]; then npm ci --include=optional; else npm install --include=optional; fi +COPY tsconfig.json ./ +COPY src/ ./src/ +RUN npm run build + +FROM node:18-alpine +WORKDIR /app +ENV NODE_ENV=production +COPY package.json package-lock.json* ./ +RUN if [ -f package-lock.json ]; then npm ci --omit=dev --include=optional; else npm install --omit=dev --include=optional; fi && npm cache clean --force +COPY --from=builder /app/dist/ ./dist/ +RUN mkdir -p /home/node/.relayplane && \ + chown -R node:node /home/node/.relayplane +USER node +EXPOSE 4801 +ENV RELAYPLANE_PROXY_HOST=0.0.0.0 +ENV RELAYPLANE_PROXY_PORT=4801 +ENTRYPOINT ["node", "dist/cli.js"] diff --git a/src/cli.ts b/src/cli.ts index 2f5b798..3f3c4b7 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -846,9 +846,9 @@ async function main(): Promise { process.exit(0); } - // Parse server options - let port = 4100; - let host = '127.0.0.1'; + // Parse server options (env vars provide defaults, CLI flags override) + let port = parseInt(process.env.RELAYPLANE_PROXY_PORT ?? '4100', 10); + let host = process.env.RELAYPLANE_PROXY_HOST ?? '127.0.0.1'; let verbose = false; let audit = false; let offline = false;