From c9fa0c023ea3a7a740a8623a5e6af716d6559857 Mon Sep 17 00:00:00 2001 From: Armin Friedl Date: Thu, 11 Jun 2020 22:00:20 +0200 Subject: [PATCH] Prepare deployment --- .drone.yml | 16 +++++-- .gitignore | 3 +- container/Dockerfile | 13 ++++++ container/etc/nginx/conf.d/fling.conf | 43 +++++++++++++++++++ container/etc/nginx/conf.d/service.conf | 0 container/etc/nginx/conf.d/web.conf | 0 service/Dockerfile | 5 +++ service/fling/pom.xml | 4 +- .../src/main/resources/application-prod.yml | 26 +++++++++++ web/Dockerfile | 5 +++ web/fling/.env | 2 + web/fling/.env.development.local | 2 +- 12 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 container/Dockerfile create mode 100644 container/etc/nginx/conf.d/fling.conf create mode 100644 container/etc/nginx/conf.d/service.conf create mode 100644 container/etc/nginx/conf.d/web.conf create mode 100644 service/Dockerfile create mode 100644 service/fling/src/main/resources/application-prod.yml create mode 100644 web/Dockerfile create mode 100644 web/fling/.env diff --git a/.drone.yml b/.drone.yml index 1be4920..0cef013 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,11 +4,10 @@ name: default steps: - name: build-service - image: adoptopenjdk:11-hotspot + image: maven:3.6-jdk-11 commands: - - ls -al - cd service/fling - - ./mvnw -Plocal clean package + - mvn clean package - name: build-web image: node:latest @@ -16,3 +15,14 @@ steps: - ls -al - cd web/fling - npm install && CI=false npm run build + +- name: publish + image: plugins/docker + settings: + username: + from_secret: docker_username + password: + from_secret: docker_password + dockerfile: container/Dockerfile + repo: arminfriedl/fling + tags: dev diff --git a/.gitignore b/.gitignore index 5e02c19..afcc897 100644 --- a/.gitignore +++ b/.gitignore @@ -370,8 +370,7 @@ typings/ .yarn-integrity # dotenv environment variables file -.env -.env.test +.env*local # parcel-bundler cache (https://parceljs.org/) .cache diff --git a/container/Dockerfile b/container/Dockerfile new file mode 100644 index 0000000..002e7a2 --- /dev/null +++ b/container/Dockerfile @@ -0,0 +1,13 @@ +FROM debian:stable + +RUN ls -al + +RUN apt-get update -y && apt-get upgrade -y && \ + apt-get install -y nginx openjdk-11-jre && \ + mkdir -p /var/www/fling && \ + mv web/fling/build/* /var/www/fling/ && \ + rm -fr web \ + +COPY ./etc/nginx/conf.d /etc/nginx/conf.d + +ENTRYPOINT ["/bin/sh"] diff --git a/container/etc/nginx/conf.d/fling.conf b/container/etc/nginx/conf.d/fling.conf new file mode 100644 index 0000000..73bb1a0 --- /dev/null +++ b/container/etc/nginx/conf.d/fling.conf @@ -0,0 +1,43 @@ +server { + listen 3000; + listen [::]:3000; + server_name _; + root /var/html/fling; + + # config to enable HSTS(HTTP Strict Transport Security) + add_header Strict-Transport-Security "max-age=15552000; includeSubdomains;"; + + # forward /api requests to tomcat + location /api { + proxy_pass http://localhost:8080; + + proxy_set_header X-Forwarded-Host $host:$server_port; + proxy_set_header X-Forwarded-Server $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto $scheme; + + # Required for web sockets to function + proxy_http_version 1.1; + proxy_buffering off; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + # Allow huge file uploads + client_max_body_size 5G; + } + + # always respond with index.html for unknown paths + # (routing is client side) + location / { + try_files $uri /index.html; + } + + error_page 404 /404.html; + location = /40x.html { + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } +} diff --git a/container/etc/nginx/conf.d/service.conf b/container/etc/nginx/conf.d/service.conf new file mode 100644 index 0000000..e69de29 diff --git a/container/etc/nginx/conf.d/web.conf b/container/etc/nginx/conf.d/web.conf new file mode 100644 index 0000000..e69de29 diff --git a/service/Dockerfile b/service/Dockerfile new file mode 100644 index 0000000..97dd06e --- /dev/null +++ b/service/Dockerfile @@ -0,0 +1,5 @@ +FROM adoptopenjdk:11-hotspot + +COPY fling fling + +ENTRYPOINT /bin/sh diff --git a/service/fling/pom.xml b/service/fling/pom.xml index e7ba82f..e1c8d4f 100644 --- a/service/fling/pom.xml +++ b/service/fling/pom.xml @@ -21,8 +21,6 @@ 1.64 0.11.1 ${project.parent.version} - - jdt_apt @@ -148,6 +146,8 @@ local local + + jdt_apt diff --git a/service/fling/src/main/resources/application-prod.yml b/service/fling/src/main/resources/application-prod.yml new file mode 100644 index 0000000..267a128 --- /dev/null +++ b/service/fling/src/main/resources/application-prod.yml @@ -0,0 +1,26 @@ +spring: + datasource: + url: jdbc:h2:mem:testdb; + driverClassName: org.h2.Driver + username: sa + password: + jpa: + hibernate.ddl-auto: update + database-platform: org.hibernate.dialect.H2Dialect + servlet: + multipart.max-file-size: -1 + multipart.max-request-size: -1 + +logging.level: + root: WARN + +fling: + archive.fileystem.directory: "/var/fling/files" + security: + allowed-origins: + - "https://friedl.net" + - "http://localhost:3000" + admin-user: "${FLING_ADMIN_USER:admin}" + admin-password: "${FLING_ADMIN_PASSWORD:123}" + signing-key: "${FLING_SIGNING_KEY:changeitchangeitchangeitchangeit}" + jwt-expiration: "${FLING_JWT_EXPIRATION:180000}" \ No newline at end of file diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..1d1d2a6 --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,5 @@ +FROM node:latest + +COPY fling fling + +ENTRYPOINT /bin/sh diff --git a/web/fling/.env b/web/fling/.env new file mode 100644 index 0000000..1ffa947 --- /dev/null +++ b/web/fling/.env @@ -0,0 +1,2 @@ +REACT_APP_API=https://fling.friedl.net/api +REACT_APP_LOGLEVEL=warn diff --git a/web/fling/.env.development.local b/web/fling/.env.development.local index 2839ac0..445b133 100644 --- a/web/fling/.env.development.local +++ b/web/fling/.env.development.local @@ -1,2 +1,2 @@ REACT_APP_API=http://localhost:8080/api -REACT_APP_LOGLEVEL=trace \ No newline at end of file +REACT_APP_LOGLEVEL=trace