diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000000..a67a63e7a81d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +# .dockerignore +Dockerfile +docker-compose.yml \ No newline at end of file diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 000000000000..d94283d44ed5 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,44 @@ +name: build & push docker container +on: + push: + tags: + - '*' + pull_request: + branches: + - main +jobs: + docker: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Docker meta + id: metal + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ github.repository }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.metal.outputs.tags }} + labels: ${{ steps.metal.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000000..af5f9a1ddc42 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM maven:3.9 AS builder + +COPY . . +RUN mvn clean install -DskipTests \ + && cd ./Mage.Server \ + && mvn package assembly:single + +FROM openjdk:8-jre + +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 + +COPY --from=builder Mage.Server/target/mage-server.zip . + +RUN unzip mage-server.zip \ + && rm mage-server.zip + +COPY dockerContainerStart.sh /xmage/ + +RUN chmod +x \ + /xmage/startServer.sh \ + /xmage/dockerContainerStart.sh + +CMD [ "./dockerContainerStart.sh" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000000..73239ddb2563 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +services: + server: + build: . + image: ghcr.io/magefree/mage + ports: + - '17171:17171' + - '17179:17179' + extra_hosts: + # Adjust this to configure the server for your deployment URL (`localhost` -> `yourDomain.com`) + - 'localhost:0.0.0.0' + environment: + # Adjust this to configure the server for your deployment URL (`localhost` -> `yourDomain.com`) + - MAGE_SERVER_ADDRESS=localhost + # 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 new file mode 100644 index 000000000000..c46df0543958 --- /dev/null +++ b/dockerContainerStart.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +XMAGE_CONFIG=/xmage/config/config.xml + +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