From b16fad103192fe70542489be85627b9046272ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Er=C3=A8be?= Date: Sun, 22 Oct 2017 14:58:16 +0200 Subject: [PATCH] Update docker file to use multistage build Former-commit-id: f7a8f5ecab5532796ca4462acc1214f5392fb6ae Former-commit-id: 0f85a545eef0467ae1d0129cdf8d992dbbb80072 [formerly 74524eb303c5ac0d8d55fe3219fb867c8104df71] [formerly 262d4dd258888853b8ca2fd24955dd26b4d78701 [formerly 3439945b19ac44d5b06e99bc35aab84155f1c48a [formerly 14d1035d3ec94627c06b8450bf2a582410f48b94] [formerly 14d1035d3ec94627c06b8450bf2a582410f48b94 [formerly 14d1035d3ec94627c06b8450bf2a582410f48b94 [formerly 962f5ddfa909bf4241f29de46a72df64ef3992ec]]]]] Former-commit-id: 73fae6474844a1512bb7eb792058194530175d92 [formerly e5d0dc67369d4f7b277734df6bc69d95cdaae79f] Former-commit-id: 58eacf41730f8f218e2a239d1407fcef512fa95e Former-commit-id: 8ad509aba4c928c1a9c41d98b66e061283a0f460 Former-commit-id: 5a3a90ac30ab3676d63a82e81c3a7e3b459b1a82 Former-commit-id: 24385ec4b9f31817ae7d33362ca609fe838324b7 [formerly f17473045c7135f4d8b91b2a7faaf42e37a78b55] Former-commit-id: e6b3cf86c980bde897cbae481443f344705fee97 --- .dockerignore | 1 + Dockerfile | 31 ++++++++++++++++++ deploy/config/wstunnel.nginx | 21 ------------ deploy/config/wstunnel.service | 13 -------- deploy/server.yml | 60 ---------------------------------- docker/Dockerfile | 13 -------- stack.yaml | 2 +- wstunnel.cabal | 1 + 8 files changed, 34 insertions(+), 108 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile delete mode 100644 deploy/config/wstunnel.nginx delete mode 100644 deploy/config/wstunnel.service delete mode 100755 deploy/server.yml delete mode 100644 docker/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8ee1bf9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.stack-work diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7fbb072 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM alpine:3.6 as builder +MAINTAINER github@erebe.eu + +RUN apk --no-cache add --repository http://dl-cdn.alpinelinux.org/alpine/edge/community \ + ca-certificates git ghc upx curl musl-dev gmp-dev zlib-dev pcre-dev +RUN curl -sSL https://get.haskellstack.org/ | sh + +COPY stack.yaml /mnt +COPY *.cabal /mnt +WORKDIR /mnt +RUN rm -rf ~/.stack && \ + stack config set system-ghc --global true && \ + stack setup && \ + stack install --split-objs --ghc-options="-fPIC -fllvm" --only-dependencies + +COPY . /mnt + +RUN stack install --split-objs --ghc-options="-fPIC -fllvm" +RUN upx --ultra-brute /root/.local/bin/wstunnel + + + +FROM alpine:latest as runner +MAINTAINER github@erebe.eu + +WORKDIR /root +COPY --from=builder /root/.local/bin/wstunnel . +RUN chmod +x ./wstunnel + +ENTRYPOINT ["./wstunnel"] + diff --git a/deploy/config/wstunnel.nginx b/deploy/config/wstunnel.nginx deleted file mode 100644 index df76e9d..0000000 --- a/deploy/config/wstunnel.nginx +++ /dev/null @@ -1,21 +0,0 @@ -server { - listen *:443 ssl; - listen [::]:443 ssl; - server_name erebe.eu; - server_name 195.154.67.145; - server_name 2001:bc8:3d8f::cafe; - - - location / { - proxy_read_timeout 1800s; - proxy_pass http://127.0.0.1:{{ listen_port }}; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - -} diff --git a/deploy/config/wstunnel.service b/deploy/config/wstunnel.service deleted file mode 100644 index 0ca3202..0000000 --- a/deploy/config/wstunnel.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=wstunnel server -Wants=network.target -After=network.target - -[Service] -Type=simple -User=wstunnel -ExecStart=/usr/local/bin/wstunnel --server ws://127.0.0.1:{{ listen_port }} -r 127.0.0.1:22 -Restart=always - -[Install] -WantedBy=multi-user.target diff --git a/deploy/server.yml b/deploy/server.yml deleted file mode 100755 index f02248b..0000000 --- a/deploy/server.yml +++ /dev/null @@ -1,60 +0,0 @@ -- hosts: server - remote_user: root - - vars: - # Username - user: wstunnel - listen_port: 9999 - - tasks: - - name: Create user {{ user }} - user: name={{ user }} - comment="{{ user }} user" - shell=/bin/false - createhome=no - - - name: Install wstunnel app - copy: src=config/wstunnel - dest=/usr/local/bin/ - owner=wstunnel - group=wstunnel - mode=u+rwx - - ################################ - # NGINX - ################################ - - name: Add nginx config - template: src=config/wstunnel.nginx - dest=/etc/nginx/sites-available/ - notify: reload nginx - - - name: Symlink nginx config - file: src=/etc/nginx/sites-available/wstunnel.nginx - dest=/etc/nginx/sites-enabled/default - state=link - - - name: Nginx started - service: name=nginx state=started enabled=true - - - ################################ - # SYSTEMD - ################################ - - name: Copy systemd service - template: src=config/wstunnel.service - dest=/usr/lib/systemd/system/ - notify: reload wstunnel - - - name: reload systemd - command: systemctl daemon-reload - - - name: wstunnel started - service: name=wstunnel state=started enabled=true - - - handlers: - - name: reload nginx - service: name=nginx state=reloaded enabled=true - - - name: reload wstunnel - service: name=wstunnel state=restarted enabled=true diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 3922d7a..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM alpine:latest -MAINTAINER github@erebe.eu - - -RUN adduser -D wstunnel -ADD https://github.com/erebe/wstunnel/blob/master/bin/wstunnel_x86_64?raw=true /home/wstunnel/wstunnel -RUN chmod +x /home/wstunnel/wstunnel - -EXPOSE 8080 -USER wstunnel - -ENTRYPOINT ["/home/wstunnel/wstunnel"] - diff --git a/stack.yaml b/stack.yaml index a9eaf31..ca707c7 100644 --- a/stack.yaml +++ b/stack.yaml @@ -15,7 +15,7 @@ # resolver: # name: custom-snapshot # location: "./custom-snapshot.yaml" -resolver: lts-7.2 +resolver: lts-9.9 # User packages to be built. # Various formats can be used as shown in the example below. diff --git a/wstunnel.cabal b/wstunnel.cabal index 112d2e4..dc123a6 100644 --- a/wstunnel.cabal +++ b/wstunnel.cabal @@ -42,6 +42,7 @@ executable wstunnel ghc-options: -threaded -O3 -rtsopts "-with-rtsopts=-N" +-- ld-options: -static build-depends: base , bytestring , classy-prelude