Skip to content

Commit

Permalink
Merge f364fb9 into 188ce35
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-nguyen committed Jul 17, 2018
2 parents 188ce35 + f364fb9 commit d9b63fd
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 51 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
**.DS_Store
**npm-debug.log

**.env*

/client/node_modules/
/client/public/bundle.js

/server/bin
/server/build/
/server/vendor/
/server/server
/server/server.exe
/server/gin-bin
/server/service-account.json
/server/service-account*.json

.inertia.toml
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ WORKDIR /client
ADD client/package.json .
RUN npm install
ADD client .
## ENV DEPENDENCY
ADD .env .
RUN npm run build

# Build server
Expand All @@ -12,6 +14,7 @@ WORKDIR /app
ENV SRC_DIR=/go/src/github.com/ubclaunchpad/bumper/server
RUN apk add --update --no-cache git
ADD server $SRC_DIR
## ENV DEPENDENCY
ADD server/service-account.json .
WORKDIR $SRC_DIR
RUN go get -u github.com/golang/dep/cmd/dep
Expand All @@ -27,6 +30,5 @@ WORKDIR /app
COPY --from=server /app/service-account.json .
COPY --from=server /app/server .

ENV PORT 9090
EXPOSE 9090
ENTRYPOINT ./server
6 changes: 2 additions & 4 deletions client/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {
const PLAYER_RADIUS = 25;
const JUNK_SIZE = 15;

const address = process.env.NODE_ENV === 'production'
? 'ws://ec2-54-193-127-203.us-west-1.compute.amazonaws.com/connect'
: 'ws://localhost:9090/connect';
const address = process.env.SERVER_URL;

export default class App extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -68,7 +66,7 @@ export default class App extends React.Component {
// connect player on load
connectPlayer() {
if (window.WebSocket) {
this.socket = new WebSocket(address);
this.socket = new WebSocket(`ws://${address}/connect`);
this.socket.onopen = () => {
this.socket.onmessage = event => this.handleMessage(JSON.parse(event.data));
};
Expand Down
30 changes: 17 additions & 13 deletions client/database/database.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import firebase from 'firebase/app';
import 'firebase/database';

const config = {
apiKey: 'AIzaSyA4CbYttLND1GH-uoLF523KYkn4tadF6rY',
authDomain: 'bumperdb-d7f48.firebaseapp.com',
databaseURL: 'https://bumperdb-d7f48.firebaseio.com',
projectId: 'bumperdb-d7f48',
storageBucket: 'bumperdb-d7f48.appspot.com',
messagingSenderId: '234111044340',
};

// When setting up a second project for Dev vs Prod:
// const config = process.env.NODE_ENV === 'production'
// ? prodConfig
// : devConfig;
const config = process.env.NODE_ENV === 'production'
? {
apiKey: 'AIzaSyA4CbYttLND1GH-uoLF523KYkn4tadF6rY',
authDomain: 'bumperdb-d7f48.firebaseapp.com',
databaseURL: 'https://bumperdb-d7f48.firebaseio.com',
projectId: 'bumperdb-d7f48',
storageBucket: 'bumperdb-d7f48.appspot.com',
messagingSenderId: '234111044340',
}
: {
apiKey: 'AIzaSyD2p9WKP5cAugArSvUD1m8aUeqZRPnCu7Q',
authDomain: 'bumperdevdb.firebaseapp.com',
databaseURL: 'https://bumperdevdb.firebaseio.com',
projectId: 'bumperdevdb',
storageBucket: 'bumperdevdb.appspot.com',
messagingSenderId: '174823897090',
};

if (!firebase.apps.length) {
firebase.initializeApp(config);
Expand Down
13 changes: 13 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --hot --host 0.0.0.0",
"build": "NODE_ENV=production webpack --config webpack.prod.js",
"build": "webpack --config webpack.prod.js",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "./node_modules/.bin/eslint . --ignore-pattern public/"
},
Expand All @@ -16,6 +16,7 @@
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"dotenv-webpack": "^1.5.7",
"firebase": "^5.1.0",
"react": "^16.2.0",
"react-bootstrap": "^0.32.1",
Expand Down
19 changes: 0 additions & 19 deletions client/public/bundle.js

This file was deleted.

8 changes: 4 additions & 4 deletions client/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
const webpack = require('webpack');
const Dotenv = require('dotenv-webpack');

const config = {
entry: './index.js',
Expand All @@ -25,9 +25,9 @@ const config = {
],
},
plugins: [
new webpack.EnvironmentPlugin([
'NODE_ENV',
]),
new Dotenv({
systemvars: true,
}),
]
};

Expand Down
11 changes: 7 additions & 4 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ services:
build:
context: .
target: client
environment:
- NODE_ENV=${NODE_ENV}
- SERVER_URL=${SERVER_URL}
volumes:
- ./client:/app
- ${PWD}/client:/app
command: npm start
ports:
- "8080:8080"
server:
build:
context: .
target: server
volumes:
- ./server:/go/src/github.com/ubclaunchpad/bumper/server
environment:
- PORT=8080
- DATABASE_URL=${DATABASE_URL}
volumes:
- ${PWD}/server:/go/src/github.com/ubclaunchpad/bumper/server
command: sh -c "go get github.com/codegangsta/gin ; gin -p 9090 -a 8080 -i run main.go"
ports:
- "9090:9090"
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
version: '3'
version: '3.4'

services:
bumper:
build: .
# network_mode: "host"
environment:
- PORT=${PORT}
- SERVER_URL=${SERVER_URL}
- DATABASE_URL=${DATABASE_URL}
ports:
- "80:9090"
- "80:${PORT}"
3 changes: 2 additions & 1 deletion server/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func ConnectDB(credentialsPath string) {
// Initialize default DB App
opt := option.WithCredentialsFile(credentialsPath)

log.Printf("Connecting to %v", os.Getenv("DATABASE_URL"))
ctx := context.Background()
config := &firebase.Config{
DatabaseURL: "https://bumperdb-d7f48.firebaseio.com",
DatabaseURL: os.Getenv("DATABASE_URL"),
}
app, err := firebase.NewApp(ctx, config, opt)
if err != nil {
Expand Down
Binary file modified server/service-account.json.enc
Binary file not shown.

0 comments on commit d9b63fd

Please sign in to comment.