-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CircleCI changes for production EKS deployment
- Loading branch information
1 parent
38d8d4c
commit 3dc4ce8
Showing
4 changed files
with
79 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
dist | ||
.dockerignore | ||
Dockerfile | ||
.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |