-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ops): integrate with circle ci / dockerize
- Loading branch information
Showing
8 changed files
with
187 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
version: 2.1 | ||
orbs: | ||
gke: circleci/[email protected] | ||
jobs: | ||
frontend-test: | ||
docker: | ||
- image: circleci/node:14.15 | ||
|
||
working_directory: ~/repo/frontend | ||
|
||
steps: | ||
- checkout: | ||
path: ~/repo | ||
- run: | ||
name: Check for changes | ||
command: ~/repo/.circleci/exit_if_path_not_changed.sh ~/repo/frontend | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
- run: | ||
name: Install Dependencies | ||
command: yarn install | ||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "package.json" }} | ||
# compile typescript | ||
- run: | ||
name: Compile Typescript | ||
command: yarn build | ||
# run tests! | ||
- run: | ||
name: Run Test Suite | ||
command: yarn test | ||
|
||
frontend-image-push: | ||
docker: | ||
- image: google/cloud-sdk | ||
|
||
working_directory: /root/project/frontend | ||
|
||
steps: | ||
- checkout: | ||
path: /root/project | ||
- run: | ||
name: Install node | ||
command: curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt-get install -y nodejs build-essential | ||
# allows docker commands | ||
- setup_remote_docker | ||
- run: | ||
name: Build docker image | ||
command: docker build --rm=false -t gcr.io/qri-io/qrimatic-fe:$CIRCLE_SHA1 . | ||
- run: | ||
name: Push image to Google Container Registry, add 'latest' tag | ||
command: ../.circleci/publish_to_gcr.sh gcr.io/qri-io/qrimatic-fe $CIRCLE_SHA1 | ||
|
||
frontend-prod-deploy: | ||
steps: | ||
- checkout | ||
- gke/install | ||
- gke/init | ||
- gke/rollout-image: | ||
deployment: qm-prod-qrimatic-fe | ||
container: qrimatic-fe | ||
image: gcr.io/qri-io/qrimatic-fe:$CIRCLE_SHA1 | ||
|
||
workflows: | ||
frontend: | ||
jobs: | ||
- frontend-test | ||
- frontend-image-push: | ||
requires: | ||
- frontend-test | ||
- frontend-prod-deploy: | ||
requires: | ||
- frontend-image-push | ||
filters: | ||
branches: | ||
only: | ||
- master |
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,45 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# source: | ||
# https://fant.io/p/circleci-early-exit/ | ||
# relevant discussion: | ||
# https://discuss.circleci.com/t/does-circleci-2-0-work-with-monorepos/10378/23 | ||
|
||
# This script makes CircleCI exit a current job if | ||
# the paths passed as an argument haven't changed. | ||
# This is eg used for preventing building native | ||
# builds unless frontend/native or frontend/shared | ||
# have changed. | ||
# | ||
# Example usage: | ||
# ./exit-if-path-not-changed.sh path/to/dir1 path/to/dir2 | ||
# | ||
# For reference: | ||
# https://gist.github.com/naesheim/18d0c0a58ee61f4674353a2f4cf71475 | ||
# https://discuss.circleci.com/t/ability-to-return-successfully-from-a-job-before-completing-all-the-next-steps/12969/4 | ||
|
||
|
||
# 1. Get all the arguments of the script | ||
# https://unix.stackexchange.com/a/197794 | ||
PATHS_TO_SEARCH="$*" | ||
|
||
# 2. Make sure the paths to search are not empty | ||
if [ -z "$PATHS_TO_SEARCH" ]; then | ||
echo "Please provide the paths to search for." | ||
echo "Example usage:" | ||
echo "./exit-if-path-not-changed.sh path/to/dir1 path/to/dir2" | ||
exit 1 | ||
fi | ||
|
||
# 3. Get the latest commit | ||
LATEST_COMMIT=$(git rev-parse HEAD) | ||
|
||
# 4. Get the latest commit in the searched paths | ||
LATEST_COMMIT_IN_PATH=$(git log -1 --format=format:%H --full-diff $PATHS_TO_SEARCH) | ||
|
||
if [ $LATEST_COMMIT != $LATEST_COMMIT_IN_PATH ]; then | ||
echo "Exiting this CircleCI job because code in the following paths have not changed:" | ||
echo $PATHS_TO_SEARCH | ||
circleci step halt | ||
fi |
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,19 @@ | ||
#!/bin/bash -u | ||
|
||
echo "publish to GCR: $1:$2, $1:latest" | ||
|
||
echo "Copy google auth file" | ||
echo $GOOGLE_AUTH > $HOME/gcp-key.json | ||
|
||
echo "Setup gcloud authentication" | ||
gcloud auth activate-service-account --key-file $HOME/gcp-key.json | ||
echo "Y\n" | gcloud auth configure-docker | ||
|
||
echo "Set gcloud project" | ||
gcloud --quiet config set project qri-io | ||
|
||
echo "Push image to google container registry" | ||
docker push $1:$2 | ||
|
||
echo "Add 'latest' tag" | ||
gcloud container images add-tag $1:$2 $1:latest |
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,7 @@ | ||
node_modules | ||
npm-debug.log | ||
build | ||
.dockerignore | ||
**/.git | ||
**/.DS_Store | ||
**/node_modules |
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,6 @@ | ||
.DS_Store | ||
*.env | ||
node_modules/ | ||
vscode/ | ||
.idea/ | ||
build/ |
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,7 @@ | ||
node_modules | ||
npm-debug.log | ||
build | ||
.dockerignore | ||
**/.git | ||
**/.DS_Store | ||
**/node_modules |
Large diffs are not rendered by default.
Oops, something went wrong.
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,20 @@ | ||
FROM node:14.15-alpine as build | ||
|
||
# create app directory | ||
WORKDIR /app | ||
|
||
# add `/app/node_modules/.bin` to $PATH | ||
ENV PATH /app/node_modules/.bin:$PATH | ||
|
||
# copy local source to /app working directory | ||
# this is affected by .dockerignore | ||
COPY . ./ | ||
# run installation | ||
RUN yarn install | ||
|
||
# distribution image, must be the same architecture & OS as build | ||
# or else node-sass gets angry | ||
FROM node:14.15-alpine | ||
COPY --from=build /app / | ||
EXPOSE 8080 | ||
CMD ["yarn", "start"] |