Skip to content

Commit

Permalink
Merge a3f7c75 into 188ce35
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-nguyen committed Jul 18, 2018
2 parents 188ce35 + a3f7c75 commit 5044a2b
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 66 deletions.
11 changes: 11 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:tickets: **Ticket(s)**: Closes #

---

## :construction_worker: Changes

A brief summary of what changes were introduced.

## :flashlight: Testing Instructions

Explain how to test your changes, if applicable.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
**.DS_Store
**.vs
**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
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Build and minify React client
FROM node:carbon AS client
WORKDIR /
## ENV DEPENDENCY
ADD .env .
WORKDIR /client
ADD client/package.json .
RUN npm install
Expand All @@ -12,6 +15,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 +31,5 @@ WORKDIR /app
COPY --from=server /app/service-account.json .
COPY --from=server /app/server .

ENV PORT 9090
EXPOSE 9090
ENTRYPOINT ./server
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ deps:
(cd server ; go get -u github.com/golang/dep/cmd/dep ; dep ensure)
(cd client ; npm install )

# Starts both the server and the client via docker-compose
.PHONY: docker-start
docker-start:
docker-compose -f docker-compose.dev.yml up

# Starts the client
.PHONY: client
client:
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ bump other players and objects off to stay alive
## Getting Started
Play the latest version [here](http://bumper.ubclaunchpad.com)!

## Docker Quickstart
Install Docker and the Docker Compose toolset. Then run:

```bash
make docker-start
```

## Manual Quickstart
## Quickstart

Go and Node are required. To install the required dependencies:

```bash
$ make deps
```

Create a .env file with the following variables and place it in the project root:
```
NODE_ENV=$YOUR_VAR
SERVER_URL=$YOUR_VAR
DATABASE_URL=$YOUR_VAR
PORT=$YOUR_VAR
```

### Run the Server

```bash
Expand Down
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
33 changes: 33 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.

11 changes: 6 additions & 5 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,10 +25,11 @@ const config = {
],
},
plugins: [
new webpack.EnvironmentPlugin([
'NODE_ENV',
]),
]
new Dotenv({
path: '../.env',
systemvars: true
}),
],
};

module.exports = config;
12 changes: 8 additions & 4 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ 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
- SERVER_URL=${SERVER_URL}
- 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"
11 changes: 8 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
version: '3'
version: '3.4'

services:
bumper:
build: .
# network_mode: "host"
env_file: .env
environment:
- PORT=${PORT}
- NODE_ENV=${NODE_ENV}
- SERVER_URL=${SERVER_URL}
- DATABASE_URL=${DATABASE_URL}
ports:
- "80:9090"
- "80:${PORT}"
8 changes: 7 additions & 1 deletion server/Gopkg.lock

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

4 changes: 4 additions & 0 deletions server/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@
[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/joho/godotenv"
version = "1.2.0"
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
14 changes: 14 additions & 0 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@ import (
"os"
"time"

"github.com/joho/godotenv"
"github.com/ubclaunchpad/bumper/server/arena"
"github.com/ubclaunchpad/bumper/server/database"
"github.com/ubclaunchpad/bumper/server/game"
"github.com/ubclaunchpad/bumper/server/models"
)

func main() {
if err := godotenv.Load("../.env"); err != nil {
log.Println("Error loading environment variables from parent directory")
log.Print("Try current directory... ")

if err := godotenv.Load(); err != nil {
log.Println("Cannot load environment variables")
} else {
log.Println("Success")
}
}

rand.Seed(time.Now().UTC().UnixNano())
arena.MessageChannel = make(chan models.Message)
game := game.CreateGame()
Expand All @@ -26,6 +38,8 @@ func main() {
http.Handle("/", http.FileServer(http.Dir("./build")))
http.Handle("/connect", game)
game.StartGame()

log.Println("Server URL: " + os.Getenv("SERVER_URL"))
log.Println("Starting server on localhost:" + os.Getenv("PORT"))
log.Println(http.ListenAndServe(":"+os.Getenv("PORT"), nil))
}
Binary file modified server/service-account.json.enc
Binary file not shown.

0 comments on commit 5044a2b

Please sign in to comment.