|
8 months ago | |
---|---|---|
app | 8 months ago | |
dist | 8 months ago | |
docker | 8 months ago | |
kubernetes | 8 months ago | |
vagrant | 8 months ago | |
.gitignore | 8 months ago | |
README.md | 8 months ago | |
docker-compose.yml | 8 months ago | |
env-example | 8 months ago |
The application provides with two, static and dynamic, builds. To build the application, run the Makefile
inside the app/
directory:
$ cd app/
$ make build # to build the dynamically-linked binary
$ make dist # to build the statically-linked binary
The static binary does not require any additional dependencies, and hence can be distributed with any package. The dist/
folder contains a statically-linked binary, which is used in one of the docker images
To run the built binary:
$ cp app/demo.bin dist/main
$ DEMO_REDIS_ADDR=":6379" DEMO_APP_ADDR=":8000" ./dist/main
This is assuming that your redis service is running on port :6379
locally, and that you want the application to listen on port :8000
. You may change these values as per your convenience.
There's two docker image builds provided inside the docker folder, one built with golang:alpine
as the base image, and the other serving the static binary inside a scratch
image. The scratch image is consists of just the go application binary and timeout
from coreutils.
To build either of the docker images, run:
$ docker build -t <project-name> -f docker/Dockerfile .
Replace Dockerfile
with Dockerfile.scratch
if you wish to build the significantly smaller scratch
image.
The built image can then be run with:
$ docker run -p 8000:8000 --net="host" <project-name>
--net
ensures that the docker uses the host network instead of the container network. This also assumes that you are running the redis service on your host machine's port :6379
. To circumvent this, provide --build-arg DEMO_REDIS_ADDR="<your-redis-host>"
while building the image.
The docker compose file builds and runs both the required services. To get started, copy the env-example
to .env
and set the APP_PORT
value in it to the port that you want to serve on. To run the compose file:
$ docker-compose -p <project-name> up -d
By default, it fetches the prebuilt thunderbottom/go-demo-app
image from dockerhub. To build your own image instead, edit the docker-compose.yml file to:
app:
build: docker/
# image: thunderbottom/go-demo-app:latest
and then you may run:
$ docker-compose -p <project-name> up -d --build
The kubernetes/
directory consists of a deployment and a service for the demo application. To deploy the application to a <namespace>
on your cluster:
$ kubectl apply -f kubernetes/app-deployment.yaml -n <namespace>
This would setup the application as a deployment on the kubernetes cluster. To access this locally, you need to port-forward:
$ kubectl port-forward -n <namespace> <pod-name> 8001:8000
This will make the application available to you on localhost:8001
.
Now, to convert the deployment into a service and to make it available through the entire cluster, run:
$ kubectl apply -f kubernetes/app-service.yaml -n <namespace>
The Vagrant image provisions a VM running ubuntu 18.04 and serves the demo application on port :8000
of the host machine. To run the vagrant file:
$ cd vagrant
$ vagrant up
Vagrant provisions the image with all the required defaults and setup, including docker and docker-compose services, and then serves the application on port :8080
of the guest machine. This can be accessed on the host machine on the :8000
port.