Guest User

watcher-go-example

a guest
Jan 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. the code in finance is just some dummy code from the watcher repo
  2.  
  3. 1. build your docker image
  4. docker build -t mywatcher:latest .
  5. 2. start compose
  6. docker-compose up -d
  7.  
  8.  
  9. ############
  10. Dockerfile
  11. ###########
  12. filename:
  13. Dockerfile
  14. #########
  15.  
  16. # get the official golang image from docker hub
  17. FROM golang:1.9
  18.  
  19. # maintainer is deprecated and new one is label
  20. LABEL maintainer="Can Yucel [can.yucel@gmail.com](mailto:can.yucel@gmail.com)"
  21.  
  22. # why are you installing those?
  23. RUN apt-get update && apt-get install -y --no-install-recommends \
  24. g++ \
  25. gcc \
  26. libc6-dev \
  27. make \
  28. pkg-config \
  29. bison \
  30. curl
  31.  
  32. # in case you want to specify the version of watcher go with the old approach, but this should be fine
  33. RUN go get github.com/canthefason/go-watcher
  34. RUN go install github.com/canthefason/go-watcher/cmd/watcher
  35.  
  36. # set the workdir (same as cd to /go/src/)
  37. # if it does not exist it gets created
  38. WORKDIR /go/src
  39.  
  40. # empty start, you can override this in your compose file
  41. CMD ["/bin/bash"]
  42.  
  43.  
  44.  
  45.  
  46. ###########
  47. docker-compose file
  48. #############
  49. filename:
  50. docker-compose.yml
  51. #############
  52.  
  53. version: "3"
  54.  
  55. services:
  56. db:
  57. image: postgres
  58. environment:
  59. POSTGRES_DB: dev
  60. POSTGRES_USER: postgres
  61. POSTGRES_PASSWORD: postgres
  62. ports:
  63. - 5432:5432
  64. app:
  65. image: mywatcher:latest
  66. command: watcher -run finance
  67. ports:
  68. - "80:8080"
  69. volumes:
  70. - .:/go/src/
  71. depends_on:
  72. - db
  73.  
  74.  
  75. #########
  76. dummy code
  77. ########
  78. filename:
  79. finance/main.go
  80. ###########
  81. package main
  82.  
  83. import (
  84. "fmt"
  85. "net/http"
  86. )
  87.  
  88. func main() {
  89. http.ListenAndServe(":7000",
  90. http.HandlerFunc(
  91. func(w http.ResponseWriter, r *http.Request) {
  92. fmt.Fprintln(w, "watcher is running now")
  93. },
  94. ),
  95. )
  96. }
Add Comment
Please, Sign In to add comment