Skip to content

Commit 2bcd78a

Browse files
committed
inital commit
1 parent 08f002d commit 2bcd78a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2171
-65
lines changed

.circleci/config.yml

+204
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# Javascript Node CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
4+
#
5+
version: 2
6+
7+
defaults: &defaults
8+
working_directory: ~/repo
9+
docker:
10+
- image: circleci/node:12-browsers
11+
12+
set_env: &set_env
13+
name: Setup Environment Variables
14+
command: |
15+
if [[ $CIRCLE_PULL_REQUEST ]]
16+
then
17+
echo 'Fetching Base Commit from GitHub'
18+
echo 'export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"' >> $BASH_ENV
19+
source $BASH_ENV
20+
echo "export CIRCLE_PR_BASE_SHA=`curl -s https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER} | jq -r '.base.sha'`" >> $BASH_ENV
21+
echo 'export AFFECTED_ARGS="--base ${CIRCLE_PR_BASE_SHA}"' >> $BASH_ENV
22+
else
23+
echo 'Fetching Base Commit from Deploy Cache'
24+
if [[ ! -f dist/last-deploy.txt ]]
25+
then
26+
mkdir dist && git rev-parse HEAD~1 > dist/last-deploy.txt
27+
fi
28+
echo 'export AFFECTED_ARGS="--base $(cat dist/last-deploy.txt)"' >> $BASH_ENV
29+
fi
30+
source $BASH_ENV
31+
echo $AFFECTED_ARGS
32+
yarn_cache: &yarn_cache
33+
keys:
34+
- node-deps-node12-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
35+
# fallback to using the latest cache if no exact match is found
36+
- node-deps-node12-
37+
38+
deploy_cache: &deploy_cache
39+
key: last-deploy-sha
40+
41+
yarn_install: &yarn_install
42+
name: Install Dependencies
43+
command: yarn install --frozen-lockfile --non-interactive
44+
45+
jobs:
46+
install:
47+
<<: *defaults
48+
steps:
49+
- checkout
50+
- restore_cache:
51+
<<: *yarn_cache
52+
- run:
53+
<<: *yarn_install
54+
- save_cache:
55+
key: node-deps-node12-{{ checksum "yarn.lock" }}
56+
paths:
57+
- ~/.cache
58+
- node_modules
59+
check-formatting:
60+
<<: *defaults
61+
steps:
62+
- checkout
63+
- restore_cache:
64+
<<: *deploy_cache
65+
- run:
66+
<<: *set_env
67+
- restore_cache:
68+
<<: *yarn_cache
69+
- run: yarn format:check ${AFFECTED_ARGS}
70+
lint:
71+
<<: *defaults
72+
steps:
73+
- checkout
74+
- restore_cache:
75+
<<: *deploy_cache
76+
- run:
77+
<<: *set_env
78+
- restore_cache:
79+
<<: *yarn_cache
80+
- run: ./node_modules/.bin/nx workspace-lint
81+
- run: yarn affected:lint ${AFFECTED_ARGS} --parallel
82+
build:
83+
<<: *defaults
84+
steps:
85+
- checkout
86+
- restore_cache:
87+
<<: *deploy_cache
88+
- run:
89+
<<: *set_env
90+
- restore_cache:
91+
<<: *yarn_cache
92+
# - run: yarn affected:build -- ${AFFECTED_ARGS} --parallel --configuration production
93+
- run: yarn affected:build -- ${AFFECTED_ARGS} --configuration production --maxWorkers=1
94+
- save_cache:
95+
key: build-{{ .Environment.CIRCLE_WORKFLOW_ID }}
96+
paths:
97+
- dist
98+
- store_artifacts:
99+
path: dist
100+
test:
101+
<<: *defaults
102+
steps:
103+
- checkout
104+
- restore_cache:
105+
<<: *deploy_cache
106+
- run:
107+
<<: *set_env
108+
- restore_cache:
109+
<<: *yarn_cache
110+
# - run: yarn affected:test -- ${AFFECTED_ARGS} --parallel -- --ci --code-coverage --maxWorkers=1
111+
- run: yarn affected:test -- ${AFFECTED_ARGS} -- --ci --code-coverage --maxWorkers=1
112+
e2e:
113+
<<: *defaults
114+
steps:
115+
- checkout
116+
- restore_cache:
117+
<<: *deploy_cache
118+
- run:
119+
<<: *set_env
120+
- restore_cache:
121+
<<: *yarn_cache
122+
- run: yarn affected:e2e -- ${AFFECTED_ARGS} --configuration production -- --headless
123+
- store_artifacts:
124+
path: dist/cypress
125+
126+
deploy:
127+
<<: *defaults
128+
steps:
129+
- checkout
130+
- restore_cache:
131+
<<: *deploy_cache
132+
- run:
133+
<<: *set_env
134+
- restore_cache:
135+
<<: *yarn_cache
136+
- restore_cache:
137+
key: build-{{ .Environment.CIRCLE_WORKFLOW_ID }}
138+
- run: echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
139+
- run: curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
140+
- run: sudo apt-get update && sudo apt-get install google-cloud-sdk
141+
- run: |
142+
echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=-
143+
gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
144+
gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
145+
- run: yarn affected -- --target deploy ${AFFECTED_ARGS}
146+
- run: git rev-parse HEAD > dist/last-deploy.txt
147+
- save_cache:
148+
key: last-deploy-sha
149+
paths:
150+
- dist/last-deploy.txt
151+
152+
workflows:
153+
version: 2
154+
pr_check:
155+
jobs:
156+
- install:
157+
filters:
158+
branches:
159+
only:
160+
- master
161+
- check-formatting:
162+
filters:
163+
branches:
164+
only:
165+
- master
166+
requires:
167+
- install
168+
- lint:
169+
filters:
170+
branches:
171+
only:
172+
- master
173+
requires:
174+
- install
175+
- test:
176+
filters:
177+
branches:
178+
only:
179+
- master
180+
requires:
181+
- install
182+
- build:
183+
filters:
184+
branches:
185+
only:
186+
- master
187+
requires:
188+
- install
189+
- e2e:
190+
filters:
191+
branches:
192+
only:
193+
- master
194+
- deploy:
195+
filters:
196+
branches:
197+
only:
198+
- master
199+
requires:
200+
- check-formatting
201+
- lint
202+
- test
203+
- build
204+
- e2e

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,42 @@ This project was generated using [Nx](https://nx.dev).
66

77
🔎 **Nx is a set of Extensible Dev Tools for Monorepos.**
88

9+
## Deployment
10+
11+
This NX workspace has been edited to enable deployment of the GraphQL API to Google Cloud Platform using Circle CI as follows:
12+
13+
- Added file `.circleci/config.yml`
14+
- Added docker file `apps/graphql-api/Dockerfile`.
15+
- Added a `deploy` task in `workspace.json` for the `architecture` property:
16+
17+
```
18+
{
19+
"graphql-api": {
20+
"root": "apps/graphql-api",
21+
"sourceRoot": "apps/graphql-api/src",
22+
"projectType": "application",
23+
"prefix": "graphql-api",
24+
"schematics": {},
25+
"architect": {
26+
"deploy": {
27+
// see workspace.json in this repo
28+
}
29+
}
30+
}
31+
}
32+
```
33+
34+
### How it works
35+
36+
When a PR is merged to master, if any code in `apps/graphql-api` or any of the libs that it depends on has change, then the `deploy` task will be executed by CircleCI as follows:
37+
38+
### References
39+
40+
- https://cloud.google.com/run/docs/quickstarts/build-and-deploy#node.js_1
41+
- https://cloud.google.com/sdk/gcloud/reference/builds/submit
42+
- https://cloud.google.com/run/docs/about-concurrency
43+
- https://circleci.com/docs/2.0/google-auth/
44+
945
## Adding capabilities to your workspace
1046

1147
Nx supports many plugins which add capabilities for developing different types of applications and different tools.

apps/front1/proxy.conf.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"/api": {
3+
"target": "http://localhost:3333",
4+
"secure": false
5+
}
6+
}

apps/front1/src/app/app.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22

33
import styled from 'styled-components';
4+
import { Box } from '@js-architecture-webinar/ui';
45

56
import { ReactComponent as Logo } from './logo.svg';
67
import star from './star.svg';
@@ -148,7 +149,9 @@ export const App = () => {
148149
<StyledApp>
149150
<header className="flex">
150151
<Logo width="75" height="75" />
151-
<h1>Welcome to front1!</h1>
152+
<Box as="h1" sx={{ backgroundColor: 'red' }}>
153+
Welcome to front1!
154+
</Box>
152155
</header>
153156
<main>
154157
<h2>Resources &amp; Tools</h2>

apps/graphql-api/.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "../../.eslintrc", "rules": {}, "ignorePatterns": ["!**/*"] }

apps/graphql-api/Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Use the official lightweight Node.js 12 image.
2+
# https://hub.docker.com/_/node
3+
FROM node:12-slim
4+
5+
# Create and change to the app directory.
6+
WORKDIR /usr/src/app
7+
8+
# Copy local code to the container image.
9+
COPY . ./
10+
11+
# Install production dependencies.
12+
RUN yarn --prod
13+
14+
# Run the web service on container startup.
15+
CMD [ "node", "main.js" ]

apps/graphql-api/jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
name: 'graphql-api',
3+
preset: '../../jest.config.js',
4+
coverageDirectory: '../../coverage/apps/graphql-api',
5+
};

apps/graphql-api/src/app/.gitkeep

Whitespace-only changes.

apps/graphql-api/src/assets/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const environment = {
2+
production: true,
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const environment = {
2+
production: false,
3+
};

apps/graphql-api/src/main.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { ApolloServer } = require('apollo-server');
2+
import { mergeResolvers, mergeTypeDefs } from '@graphql-tools/merge';
3+
// import {
4+
// typeDefs as bookTypeDefs,
5+
// resolvers as booksResolvers,
6+
// } from '@js-architecture-webinar/books';
7+
import * as books from '@js-architecture-webinar/books';
8+
9+
// The ApolloServer constructor requires two parameters: your schema
10+
// definition and your set of resolvers.
11+
const server = new ApolloServer({
12+
resolvers: mergeResolvers([books.resolvers]),
13+
typeDefs: mergeTypeDefs([books.typeDefs]),
14+
});
15+
16+
// The `listen` method launches a web server.
17+
server.listen().then(({ url }) => {
18+
console.log(`🚀 Server ready at ${url}`);
19+
});

apps/graphql-api/tsconfig.app.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"types": ["node"]
6+
},
7+
"exclude": ["**/*.spec.ts"],
8+
"include": ["**/*.ts"]
9+
}

apps/graphql-api/tsconfig.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"types": ["node", "jest", "express"]
5+
},
6+
"include": ["**/*.ts"]
7+
}

apps/graphql-api/tsconfig.spec.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "commonjs",
6+
"types": ["jest", "node"]
7+
},
8+
"include": ["**/*.spec.ts", "**/*.d.ts"]
9+
}

libs/books/.babelrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["@nrwl/react/babel"],
3+
"plugins": [["styled-components", { "pure": true, "ssr": true }]]
4+
}

0 commit comments

Comments
 (0)