Open sullof opened 7 years ago
Thank you for the suggestion. How would you recommend to allow users create and edit gin apps? Add an editor in the container (vim for instance)? Mount the volume in the host?
I don't know Gin enough to suggest an ideal solution. My goal would be keeping the Gin container as independent as possible from the app and the database.
So, I would add a local volume containing the source code. Since the initial code is generated by gin with a command like gin new app
this should be possible using the container. So, let's say that the default source code folder for Gin is /var/gin/workspace
, I would expect that I create locally a folder like ~/workspace
for my source code and, after running a container for the db, let's say mysql, I run the container with a command like
docker run -d --name some-gin -v ~/workspace:/var/gin/workspace --link some-mysql:mysql gin
After I can initialize the app running
docker exec -it some-gin gin new app
this should create the app in the /var/gin/workspace
that means that it actually creates the app in my local ~/workspace
folder. At that point I can modify my code while this is used by the container.
What I don't know is if OpenResty watches the code and updates the output in real time or has to be restarted in some way. In the second case, the approach would require something like
docker exec -it some-gin gin restart
Anyway, this is pure speculation. I don't really know how Gin works because I was unable to install it. Consider it just as a general suggestion.
Also, I guess that you can build the docker container starting FROM the openresty container Btw, I am happy to help, if I understand how to install Gin on Linux.
I did some work on this. It did require making some changes to Gin to accommodate running in a Docker container. My changes can be viewed here https://github.com/ostinelli/gin/compare/master...StevenWarren:docker
I would like to make this an alpine image but had some build issues so used Unbuntu Xenial instead. This brings the image to around 550mb. Will look at reducing that later.
NOTE: This is still very much a WIP
Docker image: https://hub.docker.com/r/manicapps/gin/
Create project root directory Create two folders in the project root app/ and data/
From project root run
docker run -v {{absolute_path_to_your_app_folder}}/app:/app --entrypoint "gin" manicapps/gin new app
Your newly created app will be in the app directory. You may now edit those files and the changes will reflect in the Docker container so long as you mount the volume.
docker run -v {{absolute_path_to_your_app_folder}}:/app --entrypoint "/bin/sh" manicapps/gin -c "cd /app && busted"
Gin will complain about port 7021 but still runs the tests properly. Need to investigate further to see why the error is thrown.
In your project root create a docker-compose.yml file.
version: "3"
services:
gin:
container_name: gin
image: manicapps/gin
volumes:
- ./app:/app
ports:
- 7200:7200
entrypoint: /bin/sh -c "cd /app && gin start --trace"
postgres:
container_name: postgres
image: postgres:9.6
restart: always
volumes:
- ./data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: appuser
In the project root run
docker-compose up
Optionally add "-d" to run as deamon.
Apologies to anyone who already tested the image, I accidentally pushed the wrong image to docker hub. It has been corrected and the proper image is now available.
@StevenWarren Do you mind sharing your Dockerfile please?
I tried to install Gin on my Macbook without success (for example,
brew pcre
fails). After I tried to install it on Linux and it was even worse. A docker container would be very useful because someone can start using Gin without caring about the complications or installs and configurations.