Skip to content

Commit b75e496

Browse files
authored
Use public url instead of s3 bucket (#154)
Use the PUBLIC_URL env var to set URLs for the various bundles, shims, replacing REACT_APP_S3_BUCKET to allow assets to be served from sub directories in our S3 bucket. * Moves web component port to 3001 from 9000 to avoid clashes with auth * Replace REACT_APP_S3_BUCKET with PUBLIC_URL everywhere * Rename the web-component bundle.js to web-component.js * Use the Webpack HTML plugin to build the web component index.html as web-component.html, and inject the bundle correctly into the body. * The web-component index is now build/web-component.html. * Adds Cypress tests to GH actions * Add a delay to CircleCI to start cypress only after the services had started. The web component works, served straight from S3, picking up the asset paths correctly: However, the editor itself does not, because it makes the assumption it is being served form the root directory. I think that is too big to cover off in this PR, and maybe we should address it in a different way.
1 parent b013c62 commit b75e496

13 files changed

Lines changed: 76 additions & 34 deletions

File tree

.circleci/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ jobs:
6363
name: Start web component server
6464
command: yarn run start:wc
6565
environment:
66-
REACT_APP_S3_BUCKET: https://editor-images-test.s3.eu-west-2.amazonaws.com
66+
PUBLIC_URL: http://localhost:3000
6767
background: true
68+
- run:
69+
name: Wait for services to be ready
70+
command: dockerize -wait http://localhost:3000 -wait http://localhost:3001 -timeout 120s
6871
- run:
6972
name: Cypress integration tests
7073
command: yarn exec cypress run

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ REACT_APP_AUTHENTICATION_CLIENT_ID='editor-dev'
22
REACT_APP_AUTHENTICATION_URL='http://localhost:9000'
33
REACT_APP_LOGIN_ENABLED='true'
44
REACT_APP_API_ENDPOINT='http://localhost:3009'
5-
REACT_APP_S3_BUCKET='http://localhost:3000'
5+
PUBLIC_URL='http://localhost:3000'

.env.webcomponent.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
REACT_APP_S3_BUCKET='http://localhost:3000'
1+
# NB This is the URL of react-ui, rather than the web component
2+
PUBLIC_URL=http://localhost:3000

.github/workflows/main.yml

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ name: Build and Upload to S3
33
on:
44
push:
55
branches:
6-
- main
7-
- 'feature/**'
8-
- 'issues/**'
6+
- '*'
97
tags:
108
- '*'
119

10+
1211
jobs:
1312
lint:
1413
runs-on: ubuntu-latest
@@ -49,8 +48,7 @@ jobs:
4948
- name: Run tests
5049
run: yarn test
5150

52-
build-deploy:
53-
needs: test
51+
test-cypress:
5452
runs-on: ubuntu-latest
5553
steps:
5654
- name: Checkout
@@ -61,14 +59,35 @@ jobs:
6159
with:
6260
node-version: 16
6361
cache: 'yarn'
64-
62+
6563
- name: Install code
6664
run: yarn install --frozen-lock-file
6765

68-
- name: Build site and WC bundle
69-
run: |
70-
yarn build
71-
yarn build:wc
66+
- name: Cypress run
67+
uses: cypress-io/github-action@v4
68+
with:
69+
install: false
70+
start: |
71+
yarn start
72+
yarn start:wc
73+
wait-on: 'http://localhost:3000, http://localhost:3001'
74+
env:
75+
PUBLIC_URL: 'http://localhost:3000'
76+
77+
build-deploy:
78+
needs:
79+
- test
80+
- test-cypress
81+
runs-on: ubuntu-latest
82+
steps:
83+
- name: Checkout
84+
uses: actions/checkout@v1
85+
86+
- name: Cache dependencies
87+
uses: actions/setup-node@v3
88+
with:
89+
node-version: 16
90+
cache: 'yarn'
7291

7392
- name: Configure AWS credentials
7493
uses: aws-actions/configure-aws-credentials@v1
@@ -102,5 +121,20 @@ jobs:
102121
fi
103122
shell: bash
104123

124+
- name: Set PUBLIC_URL
125+
run: |
126+
public_url=https://${{ env.bucket }}.s3.eu-west-2.amazonaws.com/${{ env.deploy_dir }}
127+
echo "Setting PUBLIC_URL to $public_url"
128+
echo PUBLIC_URL=$public_url >> $GITHUB_ENV
129+
shell: bash
130+
131+
- name: Install code
132+
run: yarn install --frozen-lock-file
133+
134+
- name: Build site and WC bundle
135+
run: |
136+
yarn build
137+
yarn build:wc
138+
105139
- name: Deploy site to S3 bucket
106140
run: aws s3 sync ./build/ s3://${{ env.bucket }}/${{ env.deploy_dir }} --delete

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The repo includes the Editor Web Component which shares components with the edit
5151
### `yarn stat:wc`
5252

5353
Runs the web component in development mode.
54-
Open [http://localhost:9000](http://localhost:9000) to view it in the browser.
54+
Open [http://localhost:3001](http://localhost:3001) to view it in the browser.
5555

5656
There is no production build setup for the web component at present.
5757

cypress/e2e/missionZero-wc.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const baseUrl = "http://localhost:9000"
1+
const baseUrl = "http://localhost:3001"
22

33
beforeEach(() => {
44
cy.visit(baseUrl)

cypress/e2e/spec-wc.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const baseUrl = "http://localhost:9000"
1+
const baseUrl = "http://localhost:3001"
22

33
beforeEach(() => {
44
cy.visit(baseUrl)

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
build: .
1515
command: yarn start:wc
1616
ports:
17-
- "9000:9000"
17+
- "3001:3001"
1818
container_name: react-ui-wc
1919
stdin_open: true
2020
volumes:

docs/WebComponent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ To have the web component be able to use the same React components as the site a
77

88
There is a custom webpack config file for the component `webpack.component.config.js` and a script in the `package.json`: `start:wc` which will start serving the web component.
99

10-
In `public/web-component/index.html` the JavaScript output is added and the web-component mounted. Then viewing `http://localhost:9000` will load the page with the web component mounted.
10+
In `public/web-component/index.html` the JavaScript output is added and the web-component mounted. Then viewing `http://localhost:3001` will load the page with the web component mounted.
1111

1212
## WebComponent Class
1313

src/components/AstroPiModel/FlightCase.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import Sk from "skulpt";
99

1010
const FlightCase = () => {
1111

12-
const gltf = useLoader(GLTFLoader, `${process.env.REACT_APP_S3_BUCKET}/models/raspi-compressed.glb`, loader => {
12+
const gltf = useLoader(GLTFLoader, `${process.env.PUBLIC_URL}/models/raspi-compressed.glb`, loader => {
1313
const dracoLoader = new DRACOLoader();
14-
dracoLoader.setDecoderPath( `${process.env.REACT_APP_S3_BUCKET}/three/examples/js/libs/draco/` );
14+
dracoLoader.setDecoderPath( `${process.env.PUBLIC_URL}/three/examples/js/libs/draco/` );
1515
loader.setDRACOLoader( dracoLoader );
1616
})
1717
window.mod=gltf.scene
@@ -21,17 +21,17 @@ const FlightCase = () => {
2121
var y = Math.floor(ledIndex / 8);
2222
var newMaterial = new THREE.MeshStandardMaterial({color: `rgb(${r},${g},${b})`});
2323
var object = gltf.scene.getObjectByName(`circle${x}_${7-y}-1`);
24-
24+
2525
if(object != null){
2626
object.material = newMaterial;
2727
}
2828
}
29-
29+
3030
function setPixels(indexes, pix) {
3131
if(indexes == null){
3232
indexes = Array.from(Array(8*8).keys())
3333
}
34-
34+
3535
var i = 0;
3636
for (const ledIndex of indexes){
3737
setPixel(ledIndex, pix[i][0], pix[i][1], pix[i][2])

0 commit comments

Comments
 (0)