|
| 1 | +# Dockerize Commonfare Social Wallet API |
| 2 | +The purpose of this project is to create a docker image of the |
| 3 | +Commonfare Social Wallet API service: https://github.com/Commonfare-net/social-wallet-api |
| 4 | + |
| 5 | +## How it works |
| 6 | +At a glance this is very simple and consists of the follwing steps: |
| 7 | + 1. Clone the source repository of Commonfare Social Wallet API (a.k.a SWAPI) |
| 8 | + 2. Build a dedicated image through the Dockerfile for running SWAPI service which includes all the required Clojure/Lein/Java dependencies |
| 9 | + 3. Push such image to Docker Hub |
| 10 | + |
| 11 | +## How to use it |
| 12 | +There is a `Makefile` that should help out when building a new image. |
| 13 | + |
| 14 | +### Build target |
| 15 | +Command `make docker/build` should build the image according to the provided `Dockerfile` and |
| 16 | +generate the final docker image named _commonfare/social-wallet-api_. |
| 17 | +The image is also tagged with the git tag of the original repository: |
| 18 | +``` |
| 19 | +$ docker images |
| 20 | +REPOSITORY TAG IMAGE ID CREATED SIZE |
| 21 | +commonfare/social-wallet-api latest c179ea2bd09c 8 minutes ago 767MB |
| 22 | +commonfare/social-wallet-api v0.9.3 c179ea2bd09c 8 minutes ago 767MB |
| 23 | +``` |
| 24 | +### Push target |
| 25 | +Command `make docker/push` will push the image to Docker Hub and make it publicly available |
| 26 | + |
| 27 | +### Fix target |
| 28 | +The `fix` target is a temporary solution that is in charge to comment out a line in the source |
| 29 | +code of the Social Wallet API before building the image. |
| 30 | +Such line is in the project file `project.clj` and instructs the ring web server to listen only |
| 31 | +on the `localhost` hostname. |
| 32 | + |
| 33 | +``` |
| 34 | + :ring {:init social-wallet-api.handler/init |
| 35 | + :handler social-wallet-api.handler/app |
| 36 | + ;; Accessible only from localhost |
| 37 | + ;; https://stackoverflow.com/questions/24467539/lein-ring-server-headless-only-listen-to-localhost |
| 38 | + :host "localhost" |
| 39 | + :destroy social-wallet-api.handler/destroy |
| 40 | + :reload-paths ["src"]} |
| 41 | +``` |
| 42 | + |
| 43 | +If we leave such line there we will need to use docker `host` network in order to reach the |
| 44 | +service through (for example) `localhost:3000`. |
| 45 | +As we prefer not to get container services directly using the host netwroking rather relying on |
| 46 | +their private container network we'd like to avoid it. But to do so and still be able to reach |
| 47 | +the container after some port mapping such as `<host port>:<container port>`, we need to allow |
| 48 | +the services to listen on other hostnames too. |
| 49 | + |
| 50 | +So after running the `fix` target we will get the following ad are good to go with buidling the image. |
| 51 | + |
| 52 | +``` |
| 53 | + :ring {:init social-wallet-api.handler/init |
| 54 | + :handler social-wallet-api.handler/app |
| 55 | + ;; Accessible only from localhost |
| 56 | + ;; https://stackoverflow.com/questions/24467539/lein-ring-server-headless-only-listen-to-localhost |
| 57 | + ;;:host "localhost" |
| 58 | + :destroy social-wallet-api.handler/destroy |
| 59 | + :reload-paths ["src"]} |
| 60 | +``` |
0 commit comments