dockerize app

This commit is contained in:
simon987 2020-01-03 12:25:24 -05:00
parent 816874772e
commit 482ffe960f
9 changed files with 93 additions and 16 deletions

31
Dockerfile Normal file
View File

@ -0,0 +1,31 @@
FROM golang:1.13-alpine as builder
ENV GO111MODULE=on
# Create the user and group files to run unprivileged
RUN mkdir /user && \
echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \
echo 'nobody:x:65534:' > /user/group
RUN apk update && apk add --no-cache git ca-certificates tzdata
RUN mkdir /build
COPY . /build/
WORKDIR /build
COPY ./ ./
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o architeuthis .
FROM scratch AS final
LABEL author="simon987 <me@simon987.net>"
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /user/group /user/passwd /etc/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /build/architeuthis /
COPY --from=builder /build/config.json /
WORKDIR /
USER nobody:nobody
ENTRYPOINT ["/architeuthis"]
EXPOSE 5050

View File

@ -1,14 +1,14 @@
{
"addr": "localhost:5050",
"addr": "0.0.0.0:5050",
"timeout": "15s",
"wait": "0.5s",
"multiplier": 1,
"retries": 3,
"influx_url": "http://localhost:8086",
"influx_url": "http://influxdb:8086",
"influx_user": "",
"influx_pass": "",
"max_error": 0.4,
"redis_url": "localhost:6379",
"redis_url": "redis:6379",
"hosts": [
{
"host": "*",

22
docker-compose.yml Normal file
View File

@ -0,0 +1,22 @@
version: '3'
services:
architeuthis:
build: .
ports:
- "5050:5050"
redis:
image: "redis:alpine"
# (Optional)
influxdb:
image: "influxdb"
environment:
- INFLUXDB_DB=architeuthis
grafana:
build: ./grafana
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=changeme

2
grafana/Dockerfile Normal file
View File

@ -0,0 +1,2 @@
FROM grafana/grafana
COPY ./provisioning /etc/grafana/provisioning

View File

@ -0,0 +1,12 @@
apiVersion: 1
providers:
- name: 'Architeuthis'
orgId: 1
folder: ''
type: file
disableDeletion: false
updateIntervalSeconds: 10
options:
path: /etc/grafana/provisioning/dashboards/model.json

View File

@ -15,7 +15,7 @@
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": 1,
"id": null,
"links": [],
"panels": [
{
@ -774,5 +774,5 @@
"timezone": "",
"title": "Architeuthis",
"uid": "I2xEOnbZk",
"version": 11
"version": 1
}

View File

@ -0,0 +1,10 @@
datasources:
- access: 'proxy'
editable: true
is_default: true
name: 'influx'
org_id: 1
type: 'influxdb'
url: 'http://influxdb:8086'
database: 'architeuthis'
version: 1

View File

@ -1,9 +1,14 @@
import asyncio
import sys
import requests
from proxybroker import Broker, Checker
ARCHITEUTHIS_URL = "http://localhost:5050"
if len(sys.argv) < 2:
print("Architeuthis url required")
quit(0)
ARCHITEUTHIS_URL = sys.argv[1]
def add_to_architeuthis(name, url):

15
main.go
View File

@ -9,13 +9,13 @@ import (
"github.com/sirupsen/logrus"
"html/template"
"net/http"
"strings"
"time"
)
func New() *Architeuthis {
a := new(Architeuthis)
a.reloadConfig()
a.redis = redis.NewClient(&redis.Options{
Addr: config.RedisUrl,
@ -61,7 +61,7 @@ func New() *Architeuthis {
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = fmt.Fprint(w, "{\"name\":\"Architeuthis\",\"version\":2.0}")
_, _ = fmt.Fprint(w, "{\"name\":\"Architeuthis\",\"version\":2.1}")
})
mux.HandleFunc("/add_proxy", func(w http.ResponseWriter, r *http.Request) {
@ -276,20 +276,15 @@ func main() {
logrus.SetLevel(logrus.TraceLevel)
balancer := New()
balancer.reloadConfig()
var err error
var err error = nil
balancer.influxdb, err = influx.NewHTTPClient(influx.HTTPConfig{
Addr: config.InfluxUrl,
Username: config.InfluxUser,
Password: config.InfluxPass,
})
if config.InfluxUrl != "" {
_, err = http.Post(config.InfluxUrl+"/query", "application/x-www-form-urlencoded", strings.NewReader("q=CREATE DATABASE \"architeuthis\""))
if err != nil {
panic(err)
}
if err != nil {
panic(err)
}
balancer.points = make(chan *influx.Point, InfluxDbBufferSize)