From 8b26d6ed33fb2b912148b2295792d8d5ffaf284a Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Sun, 8 Sep 2024 12:54:01 +0200 Subject: [PATCH] feat: build image from source (#3) * feat: build image from source * attempt to use latest maven to build * Update Dockerfile * fix: move unzip to final image * style: format Dockerfile * fix: typo in envvar * feat: provide usable docker-compose - both usable for local development, as well as deployment (to copy paste and work off of) * refactor: rename envvars --- Dockerfile | 51 ++++++++++++++--------------------------- docker-compose.yml | 21 ++++++++++++++++- dockerContainerStart.sh | 12 +++++----- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/Dockerfile b/Dockerfile index ee574257c2f0..b261559b87f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,46 +1,29 @@ -# build xmage -# currently fails due to mismatching versions. how did this build ever work? +FROM maven:3.9 AS builder -# FROM maven:3-jdk-8 AS builder - -# COPY . . -# RUN ls -la \ -# && mvn clean install -DskipTests \ -# && cd ./Mage.Client \ -# && ls -la \ -# && mvn package assembly:single \ -# && cd ./Mage.Server \ -# && ls -la \ -# && mvn package assembly:single \ -# && ls -la target \ -# && unzip target/mage-server.zip -d xmage-server - -# instead of building, pull from current release -FROM curlimages/curl AS builder - -WORKDIR /tmp - -RUN curl https://github.com/magefree/mage/releases/download/xmage_1.4.53V1/mage-full_1.4.53-dev_2024-08-16_15-45.zip -L -o xmage.zip \ -&& ls -la \ -&& unzip -q xmage.zip -d xmage +COPY . . +RUN mvn clean install -DskipTests \ + && cd ./Mage.Client \ + && mvn package assembly:single \ + && cd ../Mage.Server \ + && mvn package assembly:single FROM openjdk:8-jre -ENV XMAGE_DOCKER_SERVER_ADDRESS="0.0.0.0" \ - XMAGE_DOCKER_PORT="17171" \ - XMAGE_DOCKER_SEONDARY_BIND_PORT="17179" \ - XMAGE_DOCKER_MAX_SECONDS_IDLE="600" \ - XMAGE_DOCKER_AUTHENTICATION_ACTIVATED="false" \ - XMAGE_DOCKER_SERVER_NAME="mage-server" +ENV MAGE_SERVER_ADDRESS="0.0.0.0" \ + MAGE_PORT="17171" \ + MAGE_SECONDARY_BIND_PORT="17179" \ + MAGE_MAX_SECONDS_IDLE="600" \ + MAGE_AUTHENTICATION_ACTIVATED="false" \ + MAGE_SERVER_NAME="mage-server" EXPOSE 17171 17179 WORKDIR /xmage -# from being built -# COPY --from=builder /Utils/xmage-server . +COPY --from=builder Mage.Server/target/mage-server.zip . + +RUN unzip mage-server.zip \ + && rm mage-server.zip -# from release -COPY --from=builder tmp/xmage/xmage/mage-server /xmage/ COPY dockerContainerStart.sh /xmage/ RUN chmod +x \ diff --git a/docker-compose.yml b/docker-compose.yml index 4914e9e646f8..f3bdd871743b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,23 @@ services: server: build: . - # TODO + image: ghcr.io/magefree/mage + ports: + - '17171:17171' + - '17179:17179' + # Uncomment this to configure the server for your deployment URL + # extra_hosts: + # - 'your-mage-domain.com:0.0.0.0' + environment: + # Uncomment this to configure the server for your deployment URL + # - MAGE_SERVER_ADDRESS=your-mage-domain.com + # Give the server a name, if you want to + - MAGE_SERVER_NAME=mage-server + - MAGE_MAX_SECONDS_IDLE=6000 + - MAGE_AUTHENTICATION_ACTIVATED=false + volumes: + - xmage-db:/xmage/db + - xmage-saved:/xmage/saved +volumes: + xmage-db: + xmage-saved: diff --git a/dockerContainerStart.sh b/dockerContainerStart.sh index 5fae028af0cc..c46df0543958 100644 --- a/dockerContainerStart.sh +++ b/dockerContainerStart.sh @@ -2,11 +2,11 @@ XMAGE_CONFIG=/xmage/config/config.xml -sed -i -e "s#\(serverAddress=\)[\"].*[\"]#\1\"$XMAGE_DOCKER_SERVER_ADDRESS\"#g" ${XMAGE_CONFIG} -sed -i -e "s#\(serverName=\)[\"].*[\"]#\1\"$XMAGE_DOCKER_SERVER_NAME\"#g" ${XMAGE_CONFIG} -sed -i -e "s#\(port=\)[\"].*[\"]#\1\"$XMAGE_DOCKER_PORT\"#g" ${XMAGE_CONFIG} -sed -i -e "s#\(secondaryBindPort=\)[\"].*[\"]#\1\"$XMAGE_DOCKER_SEONDARY_BIND_PORT\"#g" ${XMAGE_CONFIG} -sed -i -e "s#\(maxSecondsIdle=\)[\"].*[\"]#\1\"$XMAGE_DOCKER_MAX_SECONDS_IDLE\"#g" ${XMAGE_CONFIG} -sed -i -e "s#\(authenticationActivated=\)[\"].*[\"]#\1\"$XMAGE_DOCKER_AUTHENTICATION_ACTIVATED\"#g" ${XMAGE_CONFIG} +sed -i -e "s#\(serverAddress=\)[\"].*[\"]#\1\"$MAGE_SERVER_ADDRESS\"#g" ${XMAGE_CONFIG} +sed -i -e "s#\(serverName=\)[\"].*[\"]#\1\"$MAGE_SERVER_NAME\"#g" ${XMAGE_CONFIG} +sed -i -e "s#\(port=\)[\"].*[\"]#\1\"$MAGE_PORT\"#g" ${XMAGE_CONFIG} +sed -i -e "s#\(secondaryBindPort=\)[\"].*[\"]#\1\"$MAGE_SECONDARY_BIND_PORT\"#g" ${XMAGE_CONFIG} +sed -i -e "s#\(maxSecondsIdle=\)[\"].*[\"]#\1\"$MAGE_MAX_SECONDS_IDLE\"#g" ${XMAGE_CONFIG} +sed -i -e "s#\(authenticationActivated=\)[\"].*[\"]#\1\"$MAGE_AUTHENTICATION_ACTIVATED\"#g" ${XMAGE_CONFIG} java -Xms256M -Xmx512M -XX:MaxPermSize=256m -Djava.security.policy=./config/security.policy -Djava.util.logging.config.file=./config/logging.config -Dlog4j.configuration=file:./config/log4j.properties -jar ./lib/mage-server-*.jar \ No newline at end of file