Skip to content

Commit

Permalink
Merge pull request #142 from specklesystems/cristi/fe-be-separation
Browse files Browse the repository at this point in the history
frontend / backend separation
  • Loading branch information
cristi8 authored Mar 15, 2021
2 parents 7281816 + 8fe6248 commit 32ca150
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 59 deletions.
52 changes: 0 additions & 52 deletions .circleci/Dockerfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

set -e

TARGET_SPECKLE_DEPLOYMENT=$SPECKLE_K8S_DEPLOYMENT
TARGET_SPECKLE_DEPLOYMENT=$SPECKLE_K8S_DEPLOYMENT-$SPECKLE_SERVER_PACKAGE
IMAGE_VERSION_TAG=$CIRCLE_SHA1

DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG-$SPECKLE_SERVER_PACKAGE

if [[ "$CIRCLE_TAG" =~ ^v.* ]]; then
TARGET_SPECKLE_DEPLOYMENT=$SPECKLE_K8S_DEPLOYMENT_PROD
TARGET_SPECKLE_DEPLOYMENT=$SPECKLE_K8S_DEPLOYMENT_PROD-$SPECKLE_SERVER_PACKAGE
IMAGE_VERSION_TAG=$CIRCLE_TAG
fi

docker build -t $DOCKER_IMAGE_TAG:latest . -f .circleci/Dockerfile
docker build -t $DOCKER_IMAGE_TAG:latest . -f packages/$SPECKLE_SERVER_PACKAGE/Dockerfile
docker tag $DOCKER_IMAGE_TAG:latest $DOCKER_IMAGE_TAG:$IMAGE_VERSION_TAG

echo "$DOCKER_REG_PASS" | docker login -u "$DOCKER_REG_USER" --password-stdin $DOCKER_REG_URL
Expand Down
8 changes: 5 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ jobs:
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod u+x ./kubectl
- run:
name: Create and Deploy Docker image
no_output_timeout: 30m
command: ./.circleci/ci-build-and-deploy.sh
name: Build and Deploy Frontend
command: env SPECKLE_SERVER_PACKAGE=frontend ./.circleci/build-and-deploy.sh
- run:
name: Build and Deploy Server
command: env SPECKLE_SERVER_PACKAGE=server ./.circleci/build-and-deploy.sh
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.circleci
.git
**/node_modules
**/dist
test-queries
Expand All @@ -10,4 +11,4 @@ lerna.json
.env.example
.eslintrc.json
.mocharc.js
readme.md
readme.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ packages/viewer/dist
.nyc_output
coverage/
.vscode
.idea
test-queries

**/.DS_Store
Expand Down
26 changes: 26 additions & 0 deletions packages/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# NOTE: Docker context should be set to git root directory, to include the viewer

# build stage
FROM node:14.16-buster-slim as build-stage

WORKDIR /opt/viewer
COPY packages/viewer/package*.json ./
RUN npm install
COPY packages/viewer .
RUN npm run build

WORKDIR /opt/frontend
COPY packages/frontend/package*.json ./
RUN npm install ../viewer
RUN npm ci
COPY packages/frontend .
RUN npm run build


# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /opt/frontend/dist /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY packages/frontend/nginx/nginx.conf /etc/nginx/conf.d
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
15 changes: 15 additions & 0 deletions packages/frontend/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen 80;

location / {
root /usr/share/nginx/html;
index app.html;
try_files $uri $uri/ /app.html;
}

error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /usr/share/nginx/html;
}
}
16 changes: 16 additions & 0 deletions packages/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:14.16.0-buster-slim as node

RUN apt-get update && apt-get install -y \
tini \
&& rm -rf /var/lib/apt/lists/*

ENV NODE_ENV=production
WORKDIR /app

COPY packages/server/package*.json ./
RUN npm ci

COPY packages/server .

ENTRYPOINT [ "tini", "--" ]
CMD ["node", "bin/www"]

0 comments on commit 32ca150

Please sign in to comment.