Skip to content

Commit

Permalink
Move to docker-prepare for digitalocean
Browse files Browse the repository at this point in the history
  • Loading branch information
okiyama committed Jun 19, 2024
1 parent ee8c298 commit 06614d1
Show file tree
Hide file tree
Showing 157 changed files with 2,855 additions and 2,863 deletions.
48 changes: 27 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,37 @@ buildscript {
}

plugins {
id("java")
id("org.jetbrains.kotlin.jvm") version "2.0.0"
id("org.springframework.boot") version "3.3.0"
id("io.spring.dependency-management") version "1.1.5"
id("org.jetbrains.kotlin.plugin.spring") version "2.0.0"
id("com.google.cloud.tools.jib") version "3.4.3"
id 'org.springframework.boot' version '3.3.0'
id 'io.spring.dependency-management' version '1.1.5'
id 'org.jetbrains.kotlin.jvm' version '2.0.0'
id 'org.jetbrains.kotlin.plugin.spring' version '2.0.0'
id 'com.google.cloud.tools.jib' version '3.4.3'
id "com.garyclayburg.dockerprepare" version "1.4.1"
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-websocket:3.3.0'
implementation 'org.jetbrains.kotlin:kotlin-reflect:2.0.0'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.17.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1'
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.734'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:2.0.0'
}

jib {
from {
image = 'bitnami/java:22-debian-12'
image = 'bitnami/java:21-debian-12'
}
to {
image = 'julesjulesandjulian/writeshite-backend:latest'
Expand All @@ -36,20 +56,6 @@ bootRun {
systemProperties System.properties
}

repositories {
mavenCentral()
}

dependencies {
implementation "org.springframework.boot:spring-boot-starter-websocket:3.3.0"
implementation "org.jetbrains.kotlin:kotlin-reflect:2.0.0"
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.17.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1"
implementation "com.amazonaws:aws-java-sdk-s3:1.12.734"
implementation "javax.xml.bind:jaxb-api:2.3.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib:2.0.0"
}

configurations {
all*.exclude group: "commons-logging", module: "commons-logging"
}
Expand Down
20 changes: 20 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Build and push backend image
./gradlew jib --image=julesjulesandjulian/writeshite-backend:latest

# Build frontend
(cd src/frontend || exit;
npm install
npm run build)

# Build and push frontend image
docker build -t julesjulesandjulian/writeshite-frontend:latest .
docker push julesjulesandjulian/writeshite-frontend:latest

ssh [email protected]

git clone https://github.com/Jules-Jules-and-Julian-LLC/writeshite.com.git writeshite
cd writeshite/docker || exit
docker-compose pull
docker-compose up -d
46 changes: 46 additions & 0 deletions docker-prepare/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM openjdk:8u151-jre-alpine
# We choose this base image because:
# 1. it is the latest Java 8 version on alpine as of March 2018
# 2. jre-alpine instead of jdk-alpine is much smaller but still enough to
# run most microservice applications on the JVM
# 3. jre-alpine has a smaller security footprint than other official Java docker images
# 4. the explicit version number means the build will be repeatable
# i.e. not dependent on what :latest version may have been pulled from a
# docker registry before.

RUN adduser -D -s /bin/sh springboot
COPY ./bootrunner.sh /home/springboot/bootrunner.sh
RUN chmod 755 /home/springboot/bootrunner.sh && chown springboot:springboot /home/springboot/bootrunner.sh
WORKDIR /home/springboot
USER springboot
# We add a special springboot user for running our application.
# Java applications do not need to be run as root

ADD commonServiceDependenciesLayer1 /home/springboot/app/
# This layer is composed of all transitive dependencies of a
# commonService, e.g in your build.gradle:
#
#dockerprepare {
# commonService = ['org.springframework.boot:spring-boot-starter-web']
#}
#
# All 30 jar files pulled in from spring-boot-starter-web are added to this layer

ADD dependenciesLayer2/ /home/springboot/app/
# This layer contains dependent jar files of the app that aren't a
# commonService. Most of the time,
# having dependencies in this layer will take advantage of the docker build
# cache. This will give you faster build times, faster image
# uploads/downloads and reduced storage requirements.
# This layer is computed automatically from your spring boot application

ADD classesLayer3/ /home/springboot/app/
# This layer contains your application classes. It will
# likely change on each docker image build so we expect a docker cache miss.
# This layer is computed automatically from your spring boot application

VOLUME /tmp
EXPOSE 8080
ENV JAVA_OPTS="" \
SPRING_OUTPUT_ANSI_ENABLED=ALWAYS
ENTRYPOINT ["./bootrunner.sh"]
26 changes: 26 additions & 0 deletions docker-prepare/bootrunner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
date_echo(){
datestamp=$(date "+%F %T")
echo "${datestamp} $*"
}
#exec the JVM so that it will get a SIGTERM signal and the app can shutdown gracefully

if [ -d "${HOME}/app/WEB-INF" ]; then
#execute springboot expanded war, which may have been constructed from several image layers
date_echo "exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -cp ${HOME}/app org.springframework.boot.loader.WarLauncher $*"
# shellcheck disable=SC2086
exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -cp "${HOME}/app" org.springframework.boot.loader.WarLauncher "$@"
elif [ -d "${HOME}/app" ]; then
#execute springboot expanded jar, which may have been constructed from several image layers
date_echo "exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -cp ${HOME}/app org.springframework.boot.loader.JarLauncher $*"
# shellcheck disable=SC2086
exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -cp "${HOME}/app" org.springframework.boot.loader.JarLauncher "$@"
elif [ -f "${HOME}/app.jar" ]; then
# execute springboot jar
date_echo "exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar ${HOME}/app.jar $*"
# shellcheck disable=SC2086
exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar "${HOME}/app.jar" "$@"
else
date_echo "springboot application not found in ${HOME}/app or ${HOME}/app.jar"
exit 1
fi
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions docker-prepare/classesLayer3/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Manifest-Version: 1.0
Main-Class: org.springframework.boot.loader.launch.JarLauncher
Start-Class: com.writinggame.ApplicationKt
Spring-Boot-Version: 3.3.0
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx
Build-Jdk-Spec: 17
Implementation-Title: writing.game
Implementation-Version: 1.0-SNAPSHOT

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.springframework.boot.loader.nio.file.NestedFileSystemProvider
47 changes: 47 additions & 0 deletions docker-prepare/dependenciesLayer2/BOOT-INF/classpath.idx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
- "BOOT-INF/lib/aws-java-sdk-s3-1.12.734.jar"
- "BOOT-INF/lib/aws-java-sdk-kms-1.12.734.jar"
- "BOOT-INF/lib/aws-java-sdk-core-1.12.734.jar"
- "BOOT-INF/lib/jmespath-java-1.12.734.jar"
- "BOOT-INF/lib/jackson-dataformat-cbor-2.17.1.jar"
- "BOOT-INF/lib/jackson-datatype-jdk8-2.17.1.jar"
- "BOOT-INF/lib/jackson-datatype-jsr310-2.17.1.jar"
- "BOOT-INF/lib/jackson-module-parameter-names-2.17.1.jar"
- "BOOT-INF/lib/jackson-databind-2.17.1.jar"
- "BOOT-INF/lib/jackson-annotations-2.17.1.jar"
- "BOOT-INF/lib/jackson-core-2.17.1.jar"
- "BOOT-INF/lib/jackson-module-kotlin-2.17.1.jar"
- "BOOT-INF/lib/kotlin-reflect-2.0.0.jar"
- "BOOT-INF/lib/kotlinx-coroutines-core-jvm-1.8.1.jar"
- "BOOT-INF/lib/jaxb-api-2.3.1.jar"
- "BOOT-INF/lib/kotlin-stdlib-2.0.0.jar"
- "BOOT-INF/lib/spring-messaging-6.1.8.jar"
- "BOOT-INF/lib/spring-websocket-6.1.8.jar"
- "BOOT-INF/lib/javax.activation-api-1.2.0.jar"
- "BOOT-INF/lib/annotations-23.0.0.jar"
- "BOOT-INF/lib/spring-webmvc-6.1.8.jar"
- "BOOT-INF/lib/spring-web-6.1.8.jar"
- "BOOT-INF/lib/spring-boot-autoconfigure-3.3.0.jar"
- "BOOT-INF/lib/spring-boot-3.3.0.jar"
- "BOOT-INF/lib/spring-context-6.1.8.jar"
- "BOOT-INF/lib/spring-aop-6.1.8.jar"
- "BOOT-INF/lib/spring-beans-6.1.8.jar"
- "BOOT-INF/lib/spring-expression-6.1.8.jar"
- "BOOT-INF/lib/spring-core-6.1.8.jar"
- "BOOT-INF/lib/httpclient-4.5.13.jar"
- "BOOT-INF/lib/commons-codec-1.16.1.jar"
- "BOOT-INF/lib/joda-time-2.12.7.jar"
- "BOOT-INF/lib/jakarta.annotation-api-2.1.1.jar"
- "BOOT-INF/lib/snakeyaml-2.2.jar"
- "BOOT-INF/lib/tomcat-embed-websocket-10.1.24.jar"
- "BOOT-INF/lib/tomcat-embed-core-10.1.24.jar"
- "BOOT-INF/lib/tomcat-embed-el-10.1.24.jar"
- "BOOT-INF/lib/micrometer-observation-1.13.0.jar"
- "BOOT-INF/lib/spring-jcl-6.1.8.jar"
- "BOOT-INF/lib/httpcore-4.4.16.jar"
- "BOOT-INF/lib/logback-classic-1.5.6.jar"
- "BOOT-INF/lib/log4j-to-slf4j-2.23.1.jar"
- "BOOT-INF/lib/jul-to-slf4j-2.0.13.jar"
- "BOOT-INF/lib/micrometer-commons-1.13.0.jar"
- "BOOT-INF/lib/logback-core-1.5.6.jar"
- "BOOT-INF/lib/slf4j-api-2.0.13.jar"
- "BOOT-INF/lib/log4j-api-2.23.1.jar"
10 changes: 10 additions & 0 deletions docker-prepare/dependenciesLayer2/BOOT-INF/layers.idx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- "dependencies":
- "BOOT-INF/lib/"
- "spring-boot-loader":
- "org/"
- "snapshot-dependencies":
- "application":
- "BOOT-INF/classes/"
- "BOOT-INF/classpath.idx"
- "BOOT-INF/layers.idx"
- "META-INF/"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:18-alpine
WORKDIR /app
COPY build /app/build
RUN npm install -g http-server
CMD ["http-server", "build", "-p", "3000"]
8 changes: 4 additions & 4 deletions docker/conf.d/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ server {
location /.well-known/ {}

location /websocket {
proxy_pass http://writeshite:8080;
proxy_pass http://writeshite-backend:8080;
proxy_set_header HOST $host;
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-For $remote_addr;
Expand All @@ -19,7 +19,7 @@ server {
}

location / {
proxy_pass http://writeshite:8080;
proxy_pass http://writeshite-frontend:3000;
proxy_set_header HOST $host;
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-For $remote_addr;
Expand All @@ -36,7 +36,7 @@ server {
location /.well-known/ {}

location /websocket {
proxy_pass http://writeshite:8080;
proxy_pass http://writeshite-backend:8080;
proxy_set_header HOST $host;
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-For $remote_addr;
Expand All @@ -48,7 +48,7 @@ server {
}

location / {
proxy_pass http://writeshite:8080;
proxy_pass http://writeshite-frontend:3000;
proxy_set_header HOST $host;
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-For $remote_addr;
Expand Down
21 changes: 19 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ services:
- "443:443"
volumes:
- ./conf.d:/etc/nginx/user.conf.d:ro
writeshite:
image: writeshite:1.1.0
networks:
- writeshite-net

writeshite-backend:
image: julesjulesandjulian/writeshite-backend:latest
restart: unless-stopped
networks:
- writeshite-net

writeshite-frontend:
image: julesjulesandjulian/writeshite-frontend:latest
restart: unless-stopped
ports:
- "3000:3000"
networks:
- writeshite-net

networks:
writeshite-net:
driver: bridge
Loading

0 comments on commit 06614d1

Please sign in to comment.