Skip to content

Commit

Permalink
feat: build image from source (#3)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
maybeanerd committed Sep 29, 2024
1 parent 7b4df8a commit 8315ead
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 41 deletions.
51 changes: 17 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
21 changes: 20 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
12 changes: 6 additions & 6 deletions dockerContainerStart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8315ead

Please sign in to comment.