Skip to content

Commit

Permalink
Merge branch 'develop' into feature/client-activities
Browse files Browse the repository at this point in the history
  • Loading branch information
rennemannd committed May 17, 2020
2 parents 885a80e + 56596fb commit e90e86c
Show file tree
Hide file tree
Showing 28 changed files with 1,486 additions and 1,273 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Directories
*/node_modules
cms/.tmp

# Data
cms/er_diagram.png
cms/strapi.sql
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM strapi/base

WORKDIR /usr/src/app/client

# Install client dependencies
COPY ./client/package.json .
COPY ./client/yarn.lock .
RUN yarn install

# Build client
COPY ./client .
RUN yarn build

WORKDIR /usr/src/app

# Install app dependencies
COPY ./cms/package.json .
COPY ./cms/yarn.lock .
RUN yarn install

# Bundle app source
COPY ./cms .
RUN mv ./client/build/* ./public && rm -r ./client

# Set the env to prod for build
ENV NODE_ENV production

# Build admin
RUN yarn build

# Port mapping
EXPOSE 1337

# Run when the container is started
CMD yarn start
84 changes: 69 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,91 @@
- #### `client/`
[Client](/client#client) is the frontend of the application. It is powered by [React](https://reactjs.org/) and [Blockly](https://developers.google.com/blockly).

- #### `cms/`
#### `cms/`

[Cms](/cms#cms) is the REST API and admin portal that powers the backend. It is powered by [Node](https://nodejs.org/en/) and [Strapi]().
[Cms](/cms#cms) is the REST API and admin portal that powers the backend. It is powered by [Node](https://nodejs.org/en/) and [Strapi]().

- #### `compile/`
#### `compile/`

[Compile](/compile#compile) is an arduino compiler service. It is an unofficial fork of [Chromeduino](https://github.com/spaceneedle/Chromeduino).

<br/>
<br/>

## Setup
## Environments

The project is divided into three conceptual environments.
### Development
This project's dependencies are managed through [yarn](https://classic.yarnpkg.com/en/docs/install/#mac-stable). This effectively replaces npm and should be used in place of npm everywhere except sc-compile-dev.
The following are the available scripts we can use with the client and server:

The development environment is comprised of four servers managed by docker compose.
#### Structure

The development environment is composed of four servers. The first one is run with the [Create React App](https://create-react-app.dev/docs/getting-started/) dev server. The later three are containerized with docker and run with [docker compose](https://docs.docker.com/compose/).

* `stem-c-client-dev` - localhost:3000
* `stem-c-cms-dev` - localhost:1337
* `stem-c-compile-dev` - localhost:8080
* `stem-c-db-dev` - localhost:5432

* `sc-client-dev` => localhost:3000
* `sc-cms-dev` => localhost:1337
* `sc-compile-dev` => localhost:8080
* `sc-db-dev` => localhost:3306
#### Running

To get started, simply
`stem-c-cms-dev`, `stem-c-compile-dev`, and `stem-c-db-dev`

1. Install [docker](https://docs.docker.com/get-docker/)
2. Add strapi.sql to cms/
3. Run `docker-compose up`

### Deployment
`stem-c-client-dev`

1. Run the following commands sequentially

```powershell
cd client
yarn install
yarn start
```

### Staging

#### Structure

The staging environment is deployed on Heroku. It is composed of one app running a Heroku Postgres instance and a web container.

* `stem-c-staging` - [stem-c-staging.herokuapp.com](https://stem-c-staging.herokuapp.com/)
* The web container attached to this Heroku app runs `cms` and serves static `client` build files
* The Heroku Postgres instance is attached as an add-on

#### Running

`stem-c-staging` is automatically built from the latest commits to `develop`. Heroku runs the container orchestration from there.

### Production

#### Structure

The production environment is deployed on Heroku. It is composed of two apps. One is running a Heroku Postgres instance and a web container and the other is running just a web container.

* `stem-c` - [stem-c.herokuapp.com](https://stem-c.herokuapp.com/)
* The web container attached to this Heroku app runs `cms` and serves static `client` build files
* The Heroku Postgres instance is attached as an add-on
* `stem-c-compile` - [stem-c-compile.herokuapp.com](https://stem-c-compile.herokuapp.com/)
* The web container attached to this Heroku app runs `compile`

#### Running

`stem-c` is automatically built from the latest commits to `master`. Heroku runs the container orchestration from there.

`stem-c-compile` is manually deployed through the [Container Registry](https://devcenter.heroku.com/articles/container-registry-and-runtime) and [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli).

1. Install [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli)
2. Run the following commands sequentially

TODO
```powershell
heroku login
heroku git:remote -a stem-c-compile
heroku container:login
heroku container:push web
heroku container:release web
```

<br/>

Expand All @@ -54,7 +107,8 @@ Ideally, we want our flow to resemble this. Master and develop are locked for di

### Branches

- `master` - Deployed version of the application
- `master` - Production application
- `release/<version>` - Staged version
- `develop` - Working version of the application
- `feature/<scaffold>-<feature-name>` - Based off of develop
- ex. `feature/cms-strapi`
Expand Down
11 changes: 11 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "STEM-C",
"description": "Web Blockly IDE for Arduino",
"repository": "https://github.com/STEM-C/STEM-C",
"addons": [
{
"plan": "heroku-postgresql",
"as": "DATABASE"
}
]
}
4 changes: 0 additions & 4 deletions client/.dockerignore

This file was deleted.

16 changes: 0 additions & 16 deletions client/Dockerfile

This file was deleted.

13 changes: 0 additions & 13 deletions client/docker-entrypoint.sh

This file was deleted.

3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
"last 1 firefox version",
"last 1 safari version"
]
}
},
"homepage": "."
}
4 changes: 4 additions & 0 deletions client/src/config/production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cms": "",
"compile": "https://stem-c-compile.herokuapp.com"
}
4 changes: 4 additions & 0 deletions client/src/config/staging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cms": "",
"compile": "https://stem-c-compile.herokuapp.com"
}
14 changes: 14 additions & 0 deletions client/src/hosts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import development from './config/development.json'
import staging from './config/staging.json'
import production from './config/production.json'

const getHosts = () => {
const { hostname } = window.location

if (hostname.includes('localhost')) return development
if (hostname.includes('staging')) return staging
return production
}

export const cms = getHosts().cms
export const compile = getHosts().compile
7 changes: 0 additions & 7 deletions cms/.dockerignore

This file was deleted.

25 changes: 0 additions & 25 deletions cms/Dockerfile

This file was deleted.

13 changes: 6 additions & 7 deletions cms/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
# Cms

REST API and admin portal that powers the backend. It is powered by [Node](https://nodejs.org/en/) and [Strapi](https://strapi.io/documentation/3.0.0-beta.x/getting-started/introduction.html). The file structure is defined by Strapi and is documented [here](https://strapi.io/documentation/3.0.0-beta.x/concepts/file-structure.html#files-structure).
REST API and admin portal that comprise the backend. It is powered by [Node](https://nodejs.org/en/), [Strapi](https://strapi.io/documentation/3.0.0-beta.x/getting-started/introduction.html), and [PostgreSQL](https://www.postgresql.org/). The file structure is defined by Strapi and is documented [here](https://strapi.io/documentation/3.0.0-beta.x/concepts/file-structure.html#files-structure).

<br/>

## Setup

To run Cms with the rest of the application, see the project [development](../README.md#development) setup.
**RECOMMENDED:** To run Cms with the rest of the application, see the project [development](../README.md#development) setup.

### Development

1. Install [docker](https://docs.docker.com/get-docker/)
2. Add strapi.sql to `/`
3. Start a new db container from MySQL `yarn run make-db`
3. Start a new docker container running postgres `yarn run make-db`
4. Install dependencies `yarn install`
5. Start the development server `yarn develop`

Additional scripts:

* Start an existing db container `yarn db`
* Connect to the MySQL bash `yarn db-bash`
* Start an existing db container `yarn db-start`
* Connect to the postgres bash `yarn db-bash`

<br/>

## API `/`

Built with [Node](https://nodejs.org/en/), [Koa](https://github.com/koajs/koa#readme), and [Bookshelf](https://bookshelfjs.org/), the REST API enables CRUD functionality with the application's content. Authentication is enabled via JWTs. The current database is sqlite3 running locally.
Built with [Node](https://nodejs.org/en/), [Koa](https://github.com/koajs/koa#readme), and [Bookshelf](https://bookshelfjs.org/), the REST API enables CRUD functionality with the application's content. Authentication is enabled via JWTs. The dbms is [PostgreSQL](https://www.postgresql.org/).

### Entity Relationships

Expand Down
24 changes: 11 additions & 13 deletions cms/config/environments/development/database.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@
"default": {
"connector": "bookshelf",
"settings": {
"client": "mysql",
"client": "postgres",
"host": "${process.env.DATABASE_HOST || '127.0.0.1'}",
"port": "3306",
"port": "5432",
"database": "strapi",
"username": "root",
"password": "pass"
},
"options": {}
},
"sqlite3": {
"connector": "bookshelf",
"settings": {
"client": "sqlite",
"filename": ".tmp/data.db"
"username": "postgres",
"password": "postgres"
},
"options": {
"useNullAsDefault": true
"pool": {
"min": 0,
"max": 15,
"idleTimeoutMillis": 30000,
"createTimeoutMillis": 30000,
"acquireTimeoutMillis": 30000
}
}
}
}
Expand Down
Loading

0 comments on commit e90e86c

Please sign in to comment.