zip eb.zip -r bin-
Elastic Beanstalk spins up an EC2 Instance running an NGinX reverseproxy and your app.
-
In the case of GO, you can either upload a .go source file or you can upload the compiled binary.
-
Elastic Beanstalk will run the compiled binary from /var/app/current/bin and expects the binary name to be application
-
By default, Elastic Beanstalk configures the nginx proxy to forward requests to your application on port 5000.
-
You can override the default port by setting the PORT system property to the port on which your main application listens.
- Elastic Beanstalk automatically builds the binary using the following command at deployment time:
export GOOS="linux"
export GOARCH="amd64"
mkdir bin
go build -installsuffix bin -o application application.go- The binary file can be located either at the root of the source bundle or in the bin/ directory of the source bundle.
- If you place the application binary file in both locations, Elastic Beanstalk uses the file in the bin/ directory.
##
## Do not look for C libs on the system.
## Disable cgo to create a static binary.
##
export CGO_ENABLED="0"
##
## Compile for 64-bit Linux
##
export GOOS="linux"
export GOARCH="amd64"
##
## -a : Rebuild all packages
## All imported libs will be rebuilt with CGO disabled.
##
go build -a -installsuffix bin -o application application.go- Use the empty scratch image as the base.
- Scratch is a completely empty image, which will work well with the staticly compiled go app.
- In Docker, FROM scratch is a no-op in the Dockerfile, and will not create an extra layer in your image, so the image will be as small as possible.
FROM scratch
EXPOSE 5000
ADD application /
CMD ["/application"]docker build -t gopagego .docker login --username=devokun
docker images
docker tag a39df4034764 devokun/gopagego:1
docker push devokun/gopagego- Elastic Beanstalk spins up an EC2 Instance running an NGinX reverseproxy and your docker container.
- For the docker container, you can pull from a docker repository or build an image to run.
- GOTCHA : Elastic Beanstalk will not allow you to use scratch as the base container, so you will need to choose another small container to start with like busybox.
FILE: Dockerfile
FROM busybox
EXPOSE 5000
ADD application /
CMD ["/application"]FILE : Dockerrun.aws.json
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "devokun/gopagego:1",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "5000"
}
],
"environment": [
{
"name": "ENVIRONMENT",
"value": "production"
},
{
"name": "PORT",
"value": "5000"
}
]
}