Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/continuous delivery #19

Merged
merged 24 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
92 changes: 72 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,92 @@

### `/`

- #### `client/`
[Client](/client/#client) is the frontend of the applcation. It is powered by [React](https://reactjs.org/) and [Blockly](https://developers.google.com/blockly).
#### `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 compilier service. It is an unofficial fork of [Chromeduino](https://github.com/spaceneedle/Chromeduino).
[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)
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 +105,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 @@ -31,5 +31,6 @@
"last 1 firefox version",
"last 1 safari version"
]
}
},
"homepage": "."
}
30 changes: 17 additions & 13 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, {useState, useEffect, useRef} from "react";
import AvrgirlArduino from './avrgirl-arduino';
// import * as AvrgirlArduino from './avrgirl-arduino';
import "./App.css";

import {cms, compile} from './config/development.json'
// import {cms, compile} from './config/staging.json'

import { cms, compile } from './hosts'

function App() {
let workspace;
Expand Down Expand Up @@ -41,19 +43,21 @@ function App() {
// converting base 64 to hex
Hex = atob(data.hex).toString();

const avrgirl = new AvrgirlArduino({
board: "",
debug: true
});
console.log(Hex);

// const avrgirl = new AvrgirlArduino({
// board: "",
// debug: true
// });

// TODO: Remove hardcoded file path
avrgirl.flash(Hex, (err) => {
if (err) {
console.log(err);
} else {
console.log('done correctly.');
}
})
// avrgirl.flash(Hex, (err) => {
// if (err) {
// console.log(err);
// } else {
// console.log('done correctly.');
// }
// })

});
};
Expand Down
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
Loading