Skip to content

Instantly share code, notes, and snippets.

@alldevic
Last active April 21, 2020 03:33
Show Gist options
  • Save alldevic/ff8d7c6d654c1ca05784435ee539c427 to your computer and use it in GitHub Desktop.
Save alldevic/ff8d7c6d654c1ca05784435ee539c427 to your computer and use it in GitHub Desktop.
Svelte+sapper dockerize

Svelte+sapper dockerize sample

Revision history:

  1. Add revision history
  2. Sync versions of nodejs in dev and prod images
  3. Fix incorrect nodejs version in dev image
  4. Add mode ingores from template .gitignore, remove unnecessary "npm cache clean"
  5. Add Makefile with current user, list of images, .env
  6. Fix revision history
__sapper__
.dockerignore
.gitignore
cypress/screenshots/
docker-compose.yml
Dockerfile
**/node_modules
npm-debug.log
package-lock.json
yarn-error.log
DEBUG=False
version: "3.4"
services:
frontend-dev:
container_name: frontend-dev
user: ${CURRENT_UID}
image: node:12.15.0-alpine3.11
working_dir: /app/
volumes:
- .:/app
ports:
- 3000:3000
- 10000:10000
command: >
sh -c " \
rm -rf ./node_modules/ ./src/node_modules/ package-lock.json && \
npm i && \
npm run dev \
"
networks:
default:
frontend-prod:
container_name: frontend-prod
user: ${CURRENT_UID}
build: .
ports:
- 80:3000
networks:
default:
FROM alpine:3.11.5 as build-stage
ENV NODE_ENV=production
WORKDIR /temp-app/
RUN apk add --no-cache nodejs=12.15.0-r1 && \
apk add --no-cache --virtual .build-deps npm=12.15.0-r1 && \
mkdir -p /app/
COPY package.json .
RUN npm i && \
cp -r ./node_modules /app/node_modules && \
npm i --only=dev
COPY . .
RUN npm run build && \
cp -r /temp-app/__sapper__/ /app/__sapper__/ && \
cp -r /temp-app/static/ /app/static/ && \
apk --purge del .build-deps && \
rm -rf /root/.cache /root/.local /root/.npm /root/.config /tmp/* \
/etc/apk/ /usr/share/apk/ /lib/apk/ /sbin/apk /media /usr/lib/terminfo \
/usr/share/terminfo /var/cache/apk /var/lib/apk /temp-app
FROM scratch as deploy-stage
ENV NODE_ENV=production
COPY --from=build-stage / /
WORKDIR /app/
EXPOSE 3000
ENTRYPOINT [ "node", "__sapper__/build" ]
#!/usr/bin/make
include .env
export
SHELL = /bin/sh
CURRENT_UID := $(shell id -u):$(shell id -g)
export CURRENT_UID
ifeq ($(DEBUG), True)
IMAGES := frontend-dev
else
IMAGES := frontend-prod
endif
export IMAGES
up:
docker-compose up -d $(IMAGES)
upb:
docker-compose up -d --force-recreate --build $(IMAGES)
down:
docker-compose down
logs:
docker-compose logs -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment