Skip to content

Commit 0db23fd

Browse files
authored
Big workspaces refactor (codesandbox#304)
* Big workspaces refactor * Fix linting * Fix independent building * Fix tests * Fix CircleCI * Fix tests * Fix tests * Babel-jest * More fixes * Fix all tests * Fix Tooltip location * Add build to steps * Fix indentation * Create special script for CircleCI * Fix tooltips * Run right script * Add CircleCI workflows * Build production during tests * Fix typos * Fix babel runtime location * Add babel-runtime explicitly * Add babel runtime dependency explicitly to sandbox * Remove babel-runtime from app * Fix babel runtime problem * Change building behaviour on CircleCI * Create image for integration tests * Fix puppeteer docker image * Add more cached node_modules * Fix Puppeteer in Docker * Add deploy step * Update caches * Save production builds as artifacts * Use master branch as variable for deployment caches * Add proper deployment steps * Add double check * Remove unnecessary ignore
1 parent 19db799 commit 0db23fd

File tree

1,013 files changed

+2732
-6555
lines changed

Some content is hidden

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

1,013 files changed

+2732
-6555
lines changed

.circleci/config.yml

Lines changed: 123 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,144 @@
11
version: 2
22

33
jobs:
4-
build:
5-
working_directory: ~/codesandbox-client
4+
build-dependencies:
65
docker:
76
- image: circleci/node:9.0
8-
environment:
9-
TZ: "/usr/share/zoneinfo/Europe/Amsterdam"
7+
working_directory: ~/codesandbox-client
108
steps:
119
- checkout
1210
- restore_cache:
13-
key: dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
11+
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
1412
- run:
15-
name: Install Dependency
16-
command: yarn install && yarn add puppeteer -W
13+
name: Install Dependencies
14+
command: yarn install
1715
- save_cache:
18-
key: dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
16+
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
1917
paths:
2018
- ./node_modules
19+
- ./packages/app/node_modules
20+
- ./packages/codesandbox-api/node_modules
21+
- ./packages/common/node_modules
22+
- ./packages/homepage/node_modules
2123
- ~/.yarn-cache
2224
- run:
23-
name: Workaround for https://github.com/GoogleChrome/puppeteer/issues/290
24-
command: sh ./integration-tests/scripts/workaround-puppeteer-issue-290.sh
25+
name: Build
26+
command: yarn build:dependents
27+
- save_cache:
28+
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
29+
paths:
30+
- ~/codesandbox-client
31+
32+
build-prod:
33+
docker:
34+
- image: circleci/node:9.0
35+
working_directory: ~/codesandbox-client
36+
steps:
37+
- restore_cache:
38+
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
39+
# We do this to compare sizes from these builds with master
40+
- restore_cache:
41+
key: v1-prod-build-cache-master
2542
- run:
26-
name: Start Server
43+
name: Build Application
44+
command: yarn build:prod
45+
- save_cache:
46+
key: v1-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}
47+
paths:
48+
- ./packages/app/www
49+
- store_artifacts:
50+
path: ./www
51+
destination: www
52+
53+
test-integrations:
54+
docker:
55+
- image: codesandbox/node-puppeteer
56+
working_directory: ~/codesandbox-client
57+
steps:
58+
- restore_cache:
59+
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
60+
- run:
61+
name: Start Test Server
2762
command: yarn start:test
2863
background: true
2964
- run:
30-
name: Test
65+
name: Test Integrations
3166
command: |
32-
sleep 2
33-
yarn test:integrations -- --maxWorkers=2
67+
sleep 6
68+
yarn test:integrations
3469
- store_artifacts:
35-
path: integration-tests/tests/__image_snapshots__/__diff_output__
70+
path: packages/app/integration-tests/tests/__image_snapshots__/__diff_output__
3671
destination: image_snapshot_diff
72+
73+
test-jest:
74+
docker:
75+
- image: circleci/node:9.0
76+
working_directory: ~/codesandbox-client
77+
steps:
78+
- restore_cache:
79+
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
80+
- run:
81+
name: Test
82+
command: yarn test
83+
84+
lint:
85+
docker:
86+
- image: circleci/node:9.0
87+
working_directory: ~/codesandbox-client
88+
steps:
89+
- restore_cache:
90+
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
91+
- run:
92+
name: Lint
93+
command: yarn lint
94+
95+
deploy:
96+
docker:
97+
- image: circleci/node:9.0
98+
working_directory: ~/codesandbox-client
99+
steps:
100+
- restore_cache:
101+
key: v1-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}
102+
- add_ssh_keys:
103+
fingerprints:
104+
- "f7:f1:e6:60:96:24:d9:cd:1b:8b:c0:34:e7:ee:fa:82"
105+
- run:
106+
name: Deploy
107+
command: sh ./deploy.sh
108+
109+
workflows:
110+
version: 2
111+
build-and-test:
112+
jobs:
113+
- build-dependencies
114+
- test-integrations:
115+
requires:
116+
- build-dependencies
117+
- test-jest:
118+
requires:
119+
- build-dependencies
120+
- lint:
121+
requires:
122+
- build-dependencies
123+
- build-prod:
124+
requires:
125+
- build-dependencies
126+
- hold:
127+
type: approval
128+
filters:
129+
branches:
130+
only: master
131+
requires:
132+
- build-prod
133+
- lint
134+
- test-integrations
135+
- test-jest
136+
- deploy:
137+
filters:
138+
branches:
139+
only: master
140+
requires:
141+
- hold
142+
143+
144+

CONTRIBUTING.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
## Code Organization
44

5-
The CodeSandbox client is currently divided in to 5 parts.
5+
The CodeSandbox client is currently divided in to 5 parts. We use `lerna` to share dependencies between these parts.
66

7-
- `app`: The editor and profile page
8-
- `sandbox`: The preview pane of the editor
9-
- `embed`: The embedded version of CodeSandbox (which you can embed on medium)
10-
- `common`: The common parts between `sandbox`, `embed` and `app`
11-
- `homepage`: Homepage!
7+
- `app`: The editor, the search, profile page, the embed and the sandbox.
8+
- `homepage`: The Gatsby website of the homepage.
9+
- `codesandbox-api`: The npm package that's responsible for communication between the sandbox and the editor.
10+
- `common`: All common parts between these packages, reusable JS.
1211

1312
This version of CodeSandbox is using the production server as source of truth, this is specified by the environment variable `LOCAL_SERVER`. It's not yet possible to sign in using this version, I haven't figured out how to handle this yet.
1413

15-
**Working on your first Pull Request?** You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)
14+
**Working on your first Pull Request?** You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)
1615

1716
## Setting Up the project locally
1817

Gulpfile.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
const gulp = require('gulp');
2-
const runSequence = require('run-sequence');
32

4-
const config = require('./config/paths');
5-
6-
gulp.task('homepage', function() {
7-
return gulp
8-
.src('src/homepage/public/**/*.*')
9-
.pipe(gulp.dest(`${config.appBuild}/`));
3+
gulp.task('app', function() {
4+
return gulp.src('packages/app/www/**/*').pipe(gulp.dest('www'));
105
});
116

12-
gulp.task('static', function() {
13-
return gulp
14-
.src(`${config.staticPath}/**/*`)
15-
.pipe(gulp.dest(`${config.appBuild}/`));
16-
});
17-
18-
gulp.task('build', function(cb) {
19-
return runSequence(['homepage', 'static'], cb);
7+
gulp.task('homepage', function() {
8+
return gulp.src('packages/homepage/public/**/*').pipe(gulp.dest('www'));
209
});
2110

22-
gulp.task('default', ['build']);
11+
gulp.task('default', ['app', 'homepage']);

deploy.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#!/bin/bash
22

3-
docker build -t codesandbox/prod/client --file Dockerfile.prod . && \
4-
id=$(docker create codesandbox/prod/client) && \
53
rm -rf .deliver && \
64
mkdir .deliver && \
7-
mkdir .deliver/www && \
8-
docker cp $id:/app/www/ ./.deliver/ && \
9-
docker rm -v $id && \
5+
cp -R www .deliver && \
106
echo "Tarring build files" && \
117
tar -C .deliver -zcvf .deliver/code_sandbox_client.tar.gz www && \
128
echo "Cleaning remote tar" && \
File renamed without changes.

docker/Dockerfile.integrations

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM 'circleci/node:9.0'
2+
3+
RUN sudo apt-get update && sudo apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
4+
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
5+
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
6+
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
7+
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
8+
9+
RUN cd ~/ && yarn add puppeteer
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)