Skip to content

Commit

Permalink
CircleCI changes for production EKS deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
farisshajahan committed May 10, 2020
1 parent 38d8d4c commit 3dc4ce8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 52 deletions.
95 changes: 43 additions & 52 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,46 @@
version: 2.1 # use CircleCI 2.1
jobs: # a collection of steps
build: # runs not using Workflows must have a `build` job as entry point
working_directory: ~/care # directory where steps will run
docker: # run the steps with Docker
- image: circleci/node:10.16.3 # ...with this image as the primary container; this is where all `steps` will run
steps: # a collection of executable commands
- add_ssh_keys:
fingerprints:
- "7b:31:e5:d0:a8:97:2a:e1:b5:09:07:6f:77:6f:e5:72"
- checkout # special step to check out source code to working directory
- run:
name: update-npm
command: 'sudo npm install -g npm@latest'
- restore_cache: # special step to restore the dependency cache
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: install-npm-wee
command: npm install
- save_cache: # special step to save the dependency cache
key: dependency-cache-{{ checksum "package-lock.json" }}
paths:
- ./node_modules
- run:
name: build
command: npm run build
- run:
name: list
command: ls -lah
- run:
name: Deploy
command: |
sudo apt-get update && sudo apt-get install rsync -y
version: 2.1

echo "The branch is: $CIRCLE_BRANCH"
if [[ $CIRCLE_BRANCH = "master" ]]
then
echo "Syncing to production"
ssh-keyscan -H 3.7.18.69 >> ~/.ssh/known_hosts
rsync -avz --delete -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ProxyCommand="ssh -A -W %h:%p [email protected]"' dist/ [email protected]:/opt/care_prod/
elif [[ "$CIRCLE_BRANCH" == "develop" || "$CIRCLE_BRANCH" == "migrate-to-aws" ]]
then
echo "Syncing to dev"
ssh-keyscan -H 3.7.18.69 >> ~/.ssh/known_hosts
rsync -avz --delete -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ProxyCommand="ssh -A -W %h:%p [email protected]"' dist/ [email protected]:/opt/care/
else
echo "Not Syncing the branch $CIRCLE_BRANCH"
fi
orbs:
aws-ecr: circleci/[email protected]
aws-eks: circleci/[email protected]

# tar -czf build.tar.gz dist/
# scp build.tar.gz [email protected]:/home/netlify/releases/
# ssh [email protected] "cd /home/netlify/releases/; tar xf build.tar.gz; cp -rf /opt/care_fe/ /opt/care_fe.old; mv dist /opt/care_fe/"
workflows:
deploy-to-staging:
jobs:
- aws-ecr/build-and-push-image:
account-url: AWS_ECR_ACCOUNT_URL
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
region: AWS_DEFAULT_REGION
repo: "${ECR_REPO_NAME}"
tag: "${CIRCLE_SHA1},latest"
filters:
branches:
only: develop
- aws-eks/update-container-image:
cluster-name: "${EKS_CLUSTER_NAME}"
aws-region: "${AWS_DEFAULT_REGION}"
container-image-updates: '${EKS_CONTAINER_NAME}=${AWS_ECR_ACCOUNT_URL}/${ECR_REPO_NAME}:${CIRCLE_SHA1}'
resource-name: "${EKS_STAGING_RESOURCE_NAME}"
requires:
- aws-ecr/build-and-push-image
deploy-to-production:
jobs:
- aws-ecr/build-and-push-image:
account-url: AWS_ECR_ACCOUNT_URL
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
region: AWS_DEFAULT_REGION
repo: "${ECR_REPO_NAME}"
tag: "${CIRCLE_SHA1},production-latest"
filters:
branches:
only: master
- aws-eks/update-container-image:
cluster-name: "${EKS_CLUSTER_NAME}"
aws-region: "${AWS_DEFAULT_REGION}"
container-image-updates: '${EKS_CONTAINER_NAME}=${AWS_ECR_ACCOUNT_URL}/${ECR_REPO_NAME}:${CIRCLE_SHA1}'
resource-name: "${EKS_PRODUCTION_RESOURCE_NAME}"
requires:
- aws-ecr/build-and-push-image

5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
.dockerignore
Dockerfile
.git
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#build-stage
FROM node:lts-buster-slim as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

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

listen 80;

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

error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /usr/share/nginx/html;
}

}

0 comments on commit 3dc4ce8

Please sign in to comment.