Skip to content

Commit

Permalink
CI test for separate fe and be builds
Browse files Browse the repository at this point in the history
  • Loading branch information
cristi8 committed Mar 15, 2021
1 parent 7281816 commit 4fcfd56
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 1 deletion.
37 changes: 37 additions & 0 deletions .circleci/build-and-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -e

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-$SPECKLE_SERVER_PACKAGE
IMAGE_VERSION_TAG=$CIRCLE_TAG
fi

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
docker push $DOCKER_IMAGE_TAG:latest
docker push $DOCKER_IMAGE_TAG:$IMAGE_VERSION_TAG

# echo "$K8S_CLUSTER_CERTIFICATE" | base64 --decode > k8s_cert.crt


#./kubectl \
# --kubeconfig=/dev/null \
# --server=$K8S_SERVER \
# --certificate-authority=k8s_cert.crt \
# --token=$K8S_TOKEN \
# set image deployment/$TARGET_SPECKLE_DEPLOYMENT main=$DOCKER_IMAGE_TAG:$IMAGE_VERSION_TAG

#./kubectl \
# --kubeconfig=/dev/null \
# --server=$K8S_SERVER \
# --certificate-authority=k8s_cert.crt \
# --token=$K8S_TOKEN \
# rollout status -w deployment/$TARGET_SPECKLE_DEPLOYMENT --timeout=1m
26 changes: 26 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ workflows:
only: /^v.*/
branches:
ignore: /.*/
test-separation:
jobs:
- test_sep_build:
context: main-builds
filters:
branches:
only: cristi/fe-be-separation

jobs:
test_server:
Expand Down Expand Up @@ -76,3 +83,22 @@ jobs:
name: Create and Deploy Docker image
no_output_timeout: 30m
command: ./.circleci/ci-build-and-deploy.sh

test_sep_build:
docker:
- image: circleci/golang:1.15
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Install kubectl
command: |
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: 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;"]
14 changes: 14 additions & 0 deletions packages/frontend/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
server {
listen 80;

location / {
root /usr/share/nginx/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 4fcfd56

Please sign in to comment.