Skip to content

Commit

Permalink
Merge pull request #17 from djbe/feature/dockerfile
Browse files Browse the repository at this point in the history
Add Dockerfile
  • Loading branch information
willnode authored Apr 21, 2024
2 parents 39efabb + 39c1368 commit 5dee3b5
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# General
**/.DS_Store
**/*.md
**/LICENSE

# Git
**/.git
**/.github
**/.gitattributes
**/.gitignore

# Docker
**/.dockerignore
**/Dockerfile

# Node
**/node_modules/
**/dist
**/npm-debug.log

# Env
.env
.env.*
!.env.example

# Generated certs
.certs/
52 changes: 52 additions & 0 deletions .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: Build & Publish Postgis Test

on: # yamllint disable-line rule:truthy
schedule:
- cron: "0 0 1,15 * *" # Every 2 weeks
push:
branches:
- main
tags:
- v*
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-publish:
name: Build & Publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker GitHub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for the Docker image
id: meta
uses: docker/metadata-action@5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
56 changes: 56 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
ARG NODE_VERSION=lts

#
# --- Build Stage ---
#

FROM node:${NODE_VERSION}-alpine as build

# Install dependencies
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install --frozen-lockfile

# Copy codebase
COPY . .

#
# --- Base Stage ---
#

FROM node:${NODE_VERSION}-alpine as base

USER nobody

# Copy codebase
WORKDIR /app
COPY --from=build --chown=nobody /app/package.json /app/index.js ./
COPY --from=build --chown=nobody /app/node_modules node_modules
COPY --from=build --chown=nobody /app/src src

# Location of generated SSL certificates
VOLUME /app/.certs

#
# --- App Stage ---
#

FROM base as app

ENV NODE_ENV=production
COPY --from=build --chown=nobody /app/app.js .

# A comma-separated list of root domains to whitelist
ENV WHITELIST_HOSTS=
# A comma-separated list of root domains to blacklist
ENV BLACKLIST_HOSTS=
# The URL to redirect to when a blacklisted host is accessed
ENV BLACKLIST_REDIRECT=
# The host to enable `/stat` endpoint
ENV HOME_DOMAIN=

ENV HTTP_PORT=8080 HTTPS_PORT=8443
EXPOSE 8080 8443

ENTRYPOINT ["node"]
CMD ["app.js"]

0 comments on commit 5dee3b5

Please sign in to comment.