From e59d8bba6a7e8aa417232a405cde334072c30d4f Mon Sep 17 00:00:00 2001 From: Armin Friedl Date: Fri, 12 Jun 2020 15:31:42 +0200 Subject: [PATCH] Deploy build artifacts to nexus --- .drone.yml | 17 +++++++++- container/Dockerfile | 23 +++++++++---- container/entrypoint.sh | 7 ++++ container/etc/nginx/conf.d/fling.conf | 2 +- container/etc/nginx/conf.d/web.conf | 0 .../fling/.attach_pid38548 | 0 service/fling/pom.xml | 33 +++++++++++++++++++ .../src/main/resources/application-prod.yml | 4 +-- service/settings.xml | 22 +++++++++++++ 9 files changed, 97 insertions(+), 11 deletions(-) create mode 100755 container/entrypoint.sh delete mode 100644 container/etc/nginx/conf.d/web.conf rename container/etc/nginx/conf.d/service.conf => service/fling/.attach_pid38548 (100%) create mode 100644 service/settings.xml diff --git a/.drone.yml b/.drone.yml index 0cef013..5850895 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,16 +5,30 @@ name: default steps: - name: build-service image: maven:3.6-jdk-11 + environment: + NEXUS_USER: + from_secret: nexus_user + NEXUS_PASSWORD: + from_secret: nexus_password commands: + - mkdir -p /root/.m2 + - cp service/settings.xml /root/.m2/settings.xml - cd service/fling - - mvn clean package + - mvn -Pprod clean deploy - name: build-web image: node:latest + environment: + NEXUS_USER: + from_secret: nexus_user + NEXUS_PASSWORD: + from_secret: nexus_password commands: - ls -al - cd web/fling - npm install && CI=false npm run build + - tar czf fling-web-latest.tar.gz build/ + - curl --user "$NEXUS_USER:$NEXUS_PASSWORD" --upload-file ./fling-web-latest.tar.gz https://nexus.friedl.net/repository/build-artifacts/fling-web-latest.tar.gz - name: publish image: plugins/docker @@ -24,5 +38,6 @@ steps: password: from_secret: docker_password dockerfile: container/Dockerfile + context: ./container repo: arminfriedl/fling tags: dev diff --git a/container/Dockerfile b/container/Dockerfile index 002e7a2..c986a3e 100644 --- a/container/Dockerfile +++ b/container/Dockerfile @@ -1,13 +1,22 @@ 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 \ + apt-get install -y nginx openjdk-11-jre wget && \ + mkdir -p /var/fling/files && \ + mkdir -p /tmp/fling && \ + wget -O /tmp/fling/service.jar "https://nexus.friedl.net/service/rest/v1/search/assets/download?sort=version&maven.groupId=net.friedl&maven.artifactId=fling&maven.baseVersion=*SNAPSHOT&maven.extension=jar" && \ + wget -O /tmp/fling/web.tar.gz "https://nexus.friedl.net/repository/build-artifacts/fling-web-latest.tar.gz" && \ + tar xzf /tmp/fling/web.tar.gz -C /tmp/fling && \ + ls -al /tmp/fling && \ + mkdir -p /var/www/fling && mv /tmp/fling/build/* /var/www/fling && \ + mkdir -p /var/fling && mkdir -p /var/fling/files && \ + mv /tmp/fling/service.jar ./service.jar COPY ./etc/nginx/conf.d /etc/nginx/conf.d +COPY ./entrypoint.sh ./usr/local/bin/entrypoint.sh -ENTRYPOINT ["/bin/sh"] +VOLUME /var/fling/ + +EXPOSE 3000 + +ENTRYPOINT ["entrypoint.sh"] diff --git a/container/entrypoint.sh b/container/entrypoint.sh new file mode 100755 index 0000000..f928bc3 --- /dev/null +++ b/container/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -xe + +nginx + +java -jar service.jar diff --git a/container/etc/nginx/conf.d/fling.conf b/container/etc/nginx/conf.d/fling.conf index 73bb1a0..3651c7b 100644 --- a/container/etc/nginx/conf.d/fling.conf +++ b/container/etc/nginx/conf.d/fling.conf @@ -2,7 +2,7 @@ server { listen 3000; listen [::]:3000; server_name _; - root /var/html/fling; + root /var/www/fling; # config to enable HSTS(HTTP Strict Transport Security) add_header Strict-Transport-Security "max-age=15552000; includeSubdomains;"; diff --git a/container/etc/nginx/conf.d/web.conf b/container/etc/nginx/conf.d/web.conf deleted file mode 100644 index e69de29..0000000 diff --git a/container/etc/nginx/conf.d/service.conf b/service/fling/.attach_pid38548 similarity index 100% rename from container/etc/nginx/conf.d/service.conf rename to service/fling/.attach_pid38548 diff --git a/service/fling/pom.xml b/service/fling/pom.xml index e1c8d4f..9118ffe 100644 --- a/service/fling/pom.xml +++ b/service/fling/pom.xml @@ -137,9 +137,28 @@ + + maven-deploy-plugin + + + default-deploy + deploy + + deploy + + + + + + + nexus-snapshots + https://nexus.friedl.net/repository/maven-snapshots/ + + + @@ -168,6 +187,20 @@ + + + prod + + prod + + + + com.h2database + h2 + runtime + + + diff --git a/service/fling/src/main/resources/application-prod.yml b/service/fling/src/main/resources/application-prod.yml index 267a128..c1edb54 100644 --- a/service/fling/src/main/resources/application-prod.yml +++ b/service/fling/src/main/resources/application-prod.yml @@ -1,6 +1,6 @@ spring: datasource: - url: jdbc:h2:mem:testdb; + url: jdbc:h2:file:/var/fling/testdb;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE; driverClassName: org.h2.Driver username: sa password: @@ -18,7 +18,7 @@ fling: archive.fileystem.directory: "/var/fling/files" security: allowed-origins: - - "https://friedl.net" + - "https://fling.friedl.net" - "http://localhost:3000" admin-user: "${FLING_ADMIN_USER:admin}" admin-password: "${FLING_ADMIN_PASSWORD:123}" diff --git a/service/settings.xml b/service/settings.xml new file mode 100644 index 0000000..3fef3a2 --- /dev/null +++ b/service/settings.xml @@ -0,0 +1,22 @@ + + + + + nexus-snapshots + ${env.NEXUS_USER} + ${env.NEXUS_PASSWORD} + + + + + + + nexus + central + https://nexus.friedl.net/repository/maven-central/ + + +