Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker container for Gin #35

Open
sullof opened this issue Mar 31, 2017 · 6 comments
Open

Docker container for Gin #35

sullof opened this issue Mar 31, 2017 · 6 comments

Comments

@sullof
Copy link

sullof commented Mar 31, 2017

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.

@ostinelli
Copy link
Owner

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?

@sullof
Copy link
Author

sullof commented Apr 3, 2017

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.

@sullof
Copy link
Author

sullof commented Apr 5, 2017

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.

@StevenWarren
Copy link

StevenWarren commented May 16, 2018

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 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/

Usage

Create project root directory
Create two folders in the project root app/ and data/

Create new app

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.

Run tests

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.

Docker-compose example

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.

@StevenWarren
Copy link

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.

@mindnuts
Copy link

mindnuts commented Jul 9, 2018

@StevenWarren Do you mind sharing your Dockerfile please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants