chore: build the backend container
This commit is contained in:
parent
fc4c6bd340
commit
18fc83dfa8
6 changed files with 95 additions and 3 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
docker/.env
|
24
docker/Dockerfile.backend
Normal file
24
docker/Dockerfile.backend
Normal file
|
@ -0,0 +1,24 @@
|
|||
FROM maven:3-jdk-7 AS build
|
||||
ENV BUILD_UID=1000
|
||||
ENV BUILD=/src
|
||||
ENV MAVEN_HOME=/var/maven
|
||||
ENV MAVEN_CONFIG=/var/maven/.m2
|
||||
RUN mkdir -p $MAVEN_HOME && chown $BUILD_UID $MAVEN_HOME
|
||||
RUN mkdir -p $BUILD
|
||||
ADD .. $BUILD
|
||||
RUN chown -R $BUILD_UID $BUILD
|
||||
USER $BUILD_UID
|
||||
WORKDIR $BUILD
|
||||
RUN --mount=type=cache,target=$MAVEN_HOME/.m2,uid=$BUILD_UID mvn -e -Duser.home=$MAVEN_HOME package
|
||||
|
||||
FROM openjdk:7u211-jre-alpine
|
||||
RUN <<EOF
|
||||
set -e
|
||||
mkdir -p /app
|
||||
chown 1000 /app
|
||||
EOF
|
||||
COPY --from=build /src/legacyworlds-server/legacyworlds-server-main/target/*.jar /app/server.jar
|
||||
COPY --from=build /src/legacyworlds-server/legacyworlds-server-main/target/lib /app/lib
|
||||
ADD docker/backend-entrypoint.sh /app/entrypoint.sh
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
CMD ["server"]
|
41
docker/backend-entrypoint.sh
Executable file
41
docker/backend-entrypoint.sh
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/bin/sh
|
||||
|
||||
cd /app
|
||||
|
||||
if ! [ -z "$LW_CONFIGURE" ]; then
|
||||
if [ -z "$DB_PASSWORD_FILE" ]; then
|
||||
password="$DB_PASSWORD"
|
||||
else
|
||||
password="`cat $DB_PASSWORD_FILE`"
|
||||
fi
|
||||
cat >data-source.xml <<EOF
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
|
||||
<property name="driverClassName" value="org.postgresql.Driver" />
|
||||
<property name="url" value="jdbc:postgresql://${DB_HOST}:5432/${DB_NAME}" />
|
||||
<property name="username" value="${DB_USER}" />
|
||||
<property name="password" value="${password}" />
|
||||
</bean>
|
||||
</beans>
|
||||
EOF
|
||||
fi
|
||||
|
||||
cmd="$1"
|
||||
shift
|
||||
if [ "$cmd" == server ]; then
|
||||
exec /usr/bin/java \
|
||||
-Dlog4j.configuration=log4j.properties \
|
||||
-jar server.jar
|
||||
elif [ "$cmd" == shell ]; then
|
||||
exec /bin/sh
|
||||
elif [ "$cmd" == tool ]; then
|
||||
exec /usr/bin/java \
|
||||
-jar legacyworlds-server-main-*.jar \
|
||||
--run-tool "$*"
|
||||
else
|
||||
echo "Invalid command '$cmd'" >&2
|
||||
exit 1
|
||||
fi
|
21
docker/compose.yml
Normal file
21
docker/compose.yml
Normal file
|
@ -0,0 +1,21 @@
|
|||
name: lwb6
|
||||
|
||||
services:
|
||||
|
||||
backend:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: docker/Dockerfile.backend
|
||||
restart: always
|
||||
environment:
|
||||
LW_CONFIGURE: 1
|
||||
LW_DB_HOST: db
|
||||
LW_DB_NAME: lwb6
|
||||
LW_DB_USER: lwb6
|
||||
LW_DB_PASSWORD_FILE: /run/secrets/lw_db_password
|
||||
secrets:
|
||||
- lw_db_password
|
||||
|
||||
secrets:
|
||||
lw_db_password:
|
||||
environment: LW_DB_PASSWORD
|
5
docker/env.example
Normal file
5
docker/env.example
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Password for the database superuser
|
||||
DB_PASSWORD=hVVCS5cQG17aZBk32m0wDHAluvzgyj4n
|
||||
|
||||
# Legacyworlds database password
|
||||
LW_DB_PASSWORD=aXIQkMFFzjb4Ad7nvJgO5JhNtWxo62Du
|
6
pom.xml
6
pom.xml
|
@ -15,8 +15,8 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -69,4 +69,4 @@
|
|||
<module>legacyworlds-utils</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
|
Loading…
Reference in a new issue