From a13ffa593641c9ad1a0fa6fdf5c58408a225b9f8 Mon Sep 17 00:00:00 2001 From: Daniel Stratton Date: Wed, 9 Nov 2022 16:27:47 +1000 Subject: [PATCH] Add docker ignore file for irrelevancy. Add multi-stage docker build process. Tweak automake script to allow for running parts of it. Tweak Makefile to include c++fs for GCC <= 8 --- .dockerignore | 4 ++ Dockerfile | 54 ++++++++++++++++++++++ automake.sh | 118 +++++++++++++++++++++++++++--------------------- source/Makefile | 5 ++ 4 files changed, 130 insertions(+), 51 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..4af303277 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +Dockerfile* +.git +.github +vs2022 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..7a689a099 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,54 @@ +#syntax = docker/dockerfile:1.4.0 + +FROM quay.io/centos/centos:stream AS buildbase +#RUN yum -y install tar unzip wget glibc.i686 which sudo gcc net-tools dos2unix make gcc-c++ && yum clean all && rm -rf /var/cache/yum +RUN yum -y install tar unzip glibc.i686 gcc dos2unix make gcc-c++ && yum clean all && rm -rf /var/cache/yum +RUN mkdir -p ~/uox3 + +FROM buildbase AS buildjs +#COPY automakejs.sh /root/uox3 +COPY automake.sh /root/uox3 +COPY spidermonkey /root/uox3/spidermonkey/ +RUN find /root/uox3 -name \* -type f -exec dos2unix {} \; +#RUN cd /root/uox3 && ./automakejs.sh +RUN cd /root/uox3 && ./automake.sh 1 +CMD ["/bin/bash"] + +FROM buildbase AS buildzlib +#COPY automakezlib.sh /root/uox3 +COPY automake.sh /root/uox3 +COPY zlib /root/uox3/zlib/ +RUN find /root/uox3 -name \* -type f -exec dos2unix {} \; +#RUN cd /root/uox3 && ./automakezlib.sh +RUN cd /root/uox3 && ./automake.sh 2 +CMD ["/bin/bash"] + +FROM buildbase AS buildapp +WORKDIR /root/uox3 +RUN mkdir -p spidermonkey && mkdir -p zlib +#COPY automakeuox3.sh . +COPY automake.sh . +COPY source source/ +RUN find /root/uox3 -name \* -type f -exec dos2unix {} \; +COPY --from=buildjs /root/uox3/spidermonkey spidermonkey/ +COPY --from=buildzlib /root/uox3/zlib zlib/ +#RUN cd /root/uox3 && ./automakeuox3.sh +RUN cd /root/uox3 && ./automake.sh 3 +CMD ["/bin/bash"] + +FROM quay.io/centos/centos:stream +RUN yum -y install glibc.i686 dos2unix && yum clean all && rm -rf /var/cache/yum +RUN adduser --system --create-home uox3 +USER uox3 +RUN mkdir -p ~/app +WORKDIR /home/uox3/app +COPY --from=buildapp --chown=uox3 /root/uox3/uox3 . +COPY --chown=uox3 data data/ +COPY --chown=uox3 docs docs/ +RUN <> ~/app/run.sh +#!/usr/bin/env bash +cd ~/app +./uox3 data/uox.ini +EOF +RUN chmod 777 ~/app/run.sh && dos2unix ~/app/run.sh +CMD ["~/app/run.sh"] \ No newline at end of file diff --git a/automake.sh b/automake.sh index ee690560e..b9fb77a83 100755 --- a/automake.sh +++ b/automake.sh @@ -1,61 +1,77 @@ #!/usr/bin/env bash -echo "Building spidermonkey" -cd spidermonkey -if [ "$(uname)" = "FreeBSD" ] -then - gmake -f Makefile.ref DEFINES=-DHAVE_VA_LIST_AS_ARRAY CC=clang +if (( $# == 0 )); then + # No parameters, all stages + stage=0 else - make -f Makefile.ref DEFINES=-DHAVE_VA_LIST_AS_ARRAY CC=gcc + stage="$1" fi -$ev=$? -if [ $ev -ne 0 ]; then - echo "Unable to build spidermonkey, cannot continue" - exit $ev +if [ $stage -eq 0 ] || [ $stage -eq 1 ]; then + echo "Building spidermonkey" + cd spidermonkey + if [ "$(uname)" = "FreeBSD" ] + then + gmake -f Makefile.ref DEFINES=-DHAVE_VA_LIST_AS_ARRAY CC=clang + else + make -f Makefile.ref DEFINES=-DHAVE_VA_LIST_AS_ARRAY CC=gcc + fi + + ev=$? + if [ $ev -ne 0 ]; then + echo "Unable to build spidermonkey, cannot continue" + exit $ev + fi + if [ "$(uname)" = "Darwin" ] + then + # Mac OS X + ar rcs libjs32.a Darwin_DBG.OBJ/*.o + cp Darwin_DBG.OBJ/jsautocfg.h ./ + elif [ "$(uname)" = "FreeBSD" ] + then + ar rcs libjs32.a FreeBSD_DBG.OBJ/*.o + cp FreeBSD_DBG.OBJ/jsautocfg.h ./ + elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ] + then + # Linux + ar -r libjs32.a Linux_All_DBG.OBJ/*.o + cp Linux_All_DBG.OBJ/jsautocfg.h ./ + fi + cd .. + if [ $stage -eq 1 ]; then exit 0; fi fi -if [ "$(uname)" = "Darwin" ] -then - # Mac OS X - ar rcs libjs32.a Darwin_DBG.OBJ/*.o - cp Darwin_DBG.OBJ/jsautocfg.h ./ -elif [ "$(uname)" = "FreeBSD" ] -then - ar rcs libjs32.a FreeBSD_DBG.OBJ/*.o - cp FreeBSD_DBG.OBJ/jsautocfg.h ./ -elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ] -then - # Linux - ar -r libjs32.a Linux_All_DBG.OBJ/*.o - cp Linux_All_DBG.OBJ/jsautocfg.h ./ +if [ $stage -eq 0 ] || [ $stage -eq 2 ]; then + cd zlib + echo "Bulding zlib" + make distclean + ./configure + make + + ev=$? + if [ $ev -ne 0 ]; then + echo "Unable to build zlib, cannot continue" + exit $ev + fi + cd .. + if [ $stage -eq 2 ]; then exit 0; fi fi -cd ../zlib -echo "Bulding zlib" -make distclean -./configure -make - -$ev=$? -if [ $ev -ne 0 ]; then - echo "Unable to build zlib, cannot continue" +if [ $stage -eq 0 ] || [ $stage -eq 3 ]; then + cd source + echo "Building UOX3" + if [ "$(uname)" = "FreeBSD" ] + then + gmake + else + make + fi + ev=$? + if [ -f ./uox3 ]; then + cp uox3 .. + echo "Done! You should now find the compiled uox3 binary in the root UOX3 project directory. Copy this binary to a separate directory dedicated to running your UOX3 shard, along with the contents of the UOX3/data directory, to avoid potential git conflicts and accidental overwriting of data when pulling UOX3 updates in the future." + else + echo "uox3 output not created! Please review compile status" + fi + cd .. exit $ev fi - -cd ../source -echo "Building UOX3" -if [ "$(uname)" = "FreeBSD" ] -then - gmake -else - make -fi -ev=$? -if [ -f ./uox3 ]; then - cp uox3 .. - echo "Done! You should now find the compiled uox3 binary in the root UOX3 project directory. Copy this binary to a separate directory dedicated to running your UOX3 shard, along with the contents of the UOX3/data directory, to avoid potential git conflicts and accidental overwriting of data when pulling UOX3 updates in the future." -else - echo "uox3 output not created! Please review compile status" -fi -cd .. -exit $ev diff --git a/source/Makefile b/source/Makefile index fc62027d1..c7ef66c07 100644 --- a/source/Makefile +++ b/source/Makefile @@ -7,6 +7,7 @@ ifeq ($(PLATFORM),FreeBSD) CXX := clang++ else CXX := g++ +GCCVER8 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \<= 8) endif CXXFLAGS := -std=c++17 -O2 -pthread -Wno-shift-negative-value @@ -22,6 +23,10 @@ BUILD := ./build SRC := $(wildcard *.cpp) OBJECTS := $(SRC:%.cpp=$(BUILD)/%.o) +ifeq "$(GCCVER8)" "1" + LDFLAGS += -lstdc++fs +endif + #COMPILE := $(CXX) $(DEPFLAGS) $(CXXFLAGS) $(INCLUDE) -c all: build $(TARGET)