Skip to content

Commit

Permalink
Merge pull request #8 from bluebird-tech/aws_docker
Browse files Browse the repository at this point in the history
AWS Beanstalk
  • Loading branch information
gewo committed Dec 10, 2015
2 parents 7e07257 + b776b57 commit 3eb4938
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FROM golang:1.4.2
FROM golang:1.4.2-onbuild

RUN go get github.com/tools/godep

CMD cd /go/src/app && godep restore && go install && app
RUN cd /go/src/app
RUN godep restore
RUN go build -o bin/application
ENV PORT 3000
EXPOSE 3000
CMD ["./run"]
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

7 changes: 7 additions & 0 deletions api.go → application.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,18 @@ type Impl struct {

func (i *Impl) InitDB() {
var err error

connection := os.Getenv("DATABASE_URL")

i.DB, err = gorm.Open("postgres", connection)
if err != nil {
log.Fatalf("Got error when connect database, the error is '%v'", err)
}

if err = i.DB.DB().Ping(); err != nil {
log.Fatalf("Unable to verify connection to database: '%v'", err)
}

i.DB.LogMode(true)
}

Expand Down
45 changes: 45 additions & 0 deletions doc/AWS_EB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Deploy to Elastic Beanstalk

## 0. Run a demo application from the web ui.

> This is the fastest way to get a service role and instance profile
> -- <cite>[Service Roles, Instance Profiles, and User Policies][1]</cite>
## 1. Install the EB client

```sh
pip install --user awsebcli
# add $HOME/.local/bin to your PATH
```

## 2. Create EB app and environment

```sh
NAME=puffin-api
REGION="eu-central-1"
PASSWORD=$(pwgen 30 1)

eb init \
--region eu-central-1 \
--platform "Go 1.4 (Preconfigured - Docker)" \
$NAME

eb create $NAME \
--cname $NAME \
--region $REGION \
--database \
--database.engine postgres \
--database.user root \
--database.password $PASSWORD

echo $PASSWORD
```

## 3. Deploy a new version

```sh
eb use <environment>
eb deploy
```

[1]:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts-roles.html
4 changes: 4 additions & 0 deletions run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -x
export DATABASE_URL="postgres://${RDS_USERNAME}:${RDS_PASSWORD}@${RDS_HOSTNAME}/${RDS_DB_NAME}?sslmode=disable"
bin/application

0 comments on commit 3eb4938

Please sign in to comment.