Skip to content

Commit 518216d

Browse files
committed
intial docker multiarch instructions commit
1 parent 1a92037 commit 518216d

File tree

4 files changed

+152
-4
lines changed

4 files changed

+152
-4
lines changed

SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
* [Editing STServer.ini](guides/server-guide/linux-setup/editing-stserver.ini.md)
7474
* [Explaining bEnableModcheck](guides/server-guide/linux-setup/explaining-benablemodcheck.md)
7575
* [Port forwarding](guides/server-guide/linux-setup/port-forwarding.md)
76+
* [Build Docker server image](guides/server-guide/linux-setup/build-docker-image.md)
7677
* [Server configuration parameters](guides/server-guide/server-configuration.md)
7778
* [Troubleshooting](guides/troubleshooting/README.md)
7879
* [Address Library error](guides/troubleshooting/address-library-error.md)

guides/server-guide/linux-setup/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
In this guide, Linux users have only one option: **Docker**. Docker is very simple to set up.
66

77
### [Option 1: Docker setup](docker-setup.md)
8-
## [Option 1a: Build Docker server image](build-docker-image.md)
8+
##### [Option 1a: Build Docker server image](build-docker-image.md)
Original file line numberDiff line numberDiff line change
@@ -1 +1,146 @@
1-
### TEST
1+
# Build Multi-Architecture Docker Server Image
2+
3+
**This is an advanced guide. If you have not worked with `docker` before, it is best that you [follow the Docker setup guide](docker-setup.md) to pull the official docker image from the tiltedphoques repository on Docker Hub.**
4+
5+
This guide is primarily for those who want to build a dev branch of the server for use with Docker/Linux or for using `docker buildx` to build the server for different architectures/platforms. If you have not yet setup Docker, follow the [Installing Docker](docker-setup.md#installing-docker) instructions.
6+
7+
In order to follow these instructions, you will need to have an account on [Docker Hub](https://hub.docker.com) and you will need to be logged into that account using `docker login`. Instructions for such can be found [here](https://docs.docker.com/engine/reference/commandline/login/).
8+
9+
Below, we will be referring to your docker hub repository as `username/image_name` when we push images. Please note that anywhere you see `username` it needs to be your Docker Hub username.
10+
11+
## Setting up Docker Multiarch Builder with Buildx
12+
13+
We only need `Dockerfile` and `Dockerfile.builder` in order to build the image. We have three options to retrieve these files, you only need to choose and follow the steps in one of them.
14+
15+
#### Option 1: Clone the TiltedEvolution Repository
16+
17+
This is the writer's preference, since it will always pull the latest Dockerfile and Dockerfile.builder, and it's simple. It does download the full repo, however, which includes files unecessary for this process.
18+
19+
1. Run the following command to clone the repository into `~/str`:\
20+
`git clone https://github.com/tiltedphoques/TiltedEvolution.git ~/str`
21+
* We will not be building this project directly so we do not require the submodules/dependencies.
22+
* If you encounter an error about login status, install gh `sudo apt install gh` and login `gh auth login` to your github account.
23+
2. Change directory ~/str:\
24+
`cd ~/str`
25+
26+
#### Option 2: Download just Dockerfile and Dockerfile.builder
27+
28+
This option does not download any unecessary files, though it is a few more commands and it links directly to the necessary files. If these file names change in the future, these links may break.
29+
30+
1. Make sure `curl` is installed:\
31+
`sudo apt update && sudo apt install curl`
32+
2. Make a directory to hold the files and change to it:\
33+
`mkdir ~/str && cd ~/str`
34+
3. Download `Dockerfile`:\
35+
`curl -fsSL https://raw.githubusercontent.com/tiltedphoques/TiltedEvolution/master/Dockerfile -o Dockerfile`
36+
4. Download `Dockerfile.builder`:\
37+
`curl -fsSL https://raw.githubusercontent.com/tiltedphoques/TiltedEvolution/master/Dockerfile.builder -o Dockerfile.builder`
38+
39+
#### Option 3: Copy and Paste
40+
41+
1. Make a directory to hold the files and change to it:\
42+
`mkdir ~/str && cd ~/str`
43+
2. Create the two files we need:\
44+
`touch Dockerfile Dockerfile.builder`
45+
3. Open Dockerfile for editing:\
46+
`nano Dockerfile`
47+
4. Copy the following contents into Dockerfile and save:\
48+
```
49+
FROM username/multiarch-builder:latest as builder
50+
51+
ARG REPO=https://github.com/tiltedphoques/TiltedEvolution.git
52+
ARG BRANCH=master
53+
54+
WORKDIR /home/builder
55+
56+
ENV XMAKE_ROOT=y
57+
58+
RUN git clone --recursive -b ${BRANCH} ${REPO} ./str && \
59+
cd str && xmake config -m release -y && xmake -y && xmake install -o package -y
60+
61+
62+
# Building for x86_64
63+
FROM builder as amd64builder
64+
65+
RUN cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30 /home/builder/libstdc++.so.6
66+
67+
68+
# Building for arm64/v8
69+
FROM builder as arm64builder
70+
71+
RUN cp /usr/lib/aarch64-linux-gnu/libstdc++.so.6.0.30 /home/builder/libstdc++.so.6
72+
73+
74+
# Intermediate image that has the library specific to our $TARGETARCH
75+
FROM ${TARGETARCH}builder as intermediate
76+
# If a user has built without buildx, attempt to save them
77+
RUN if [ "${TARGETARCH}" = "" ]; then export LIBFILE="/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30"; if [ ! -e ${LIBFILE} ]; then export LIBFILE=/usr/lib/aarch64-linux-gnu/libstdc++.so.6.0.30; fi ; cp ${LIBFILE} /home/builder/libstdc++.so.6; fi
78+
79+
80+
# Build actual server image
81+
FROM ubuntu:22.04
82+
83+
COPY --from=intermediate /home/builder/str/package/lib/libSTServer.so /home/server/libSTServer.so
84+
COPY --from=intermediate /home/builder/str/package/bin/crashpad_handler /home/server/crashpad_handler
85+
COPY --from=intermediate /home/builder/str/package/bin/SkyrimTogetherServer /home/server/SkyrimTogetherServer
86+
87+
COPY --from=intermediate /home/builder/libstdc++.so.6 /home/server/libstdc++.so.6
88+
89+
WORKDIR /home/server
90+
ENTRYPOINT ["./SkyrimTogetherServer"]
91+
92+
EXPOSE 10578/udp
93+
```
94+
6. Open Dockerfile.builder for editing:\
95+
`nano Dockerfile.builder`
96+
7. Copy the following contents into Dockerfile.builder and save:\
97+
```
98+
FROM ubuntu:22.04
99+
100+
WORKDIR /home/builder
101+
102+
RUN apt update && apt install \
103+
cmake \
104+
unzip \
105+
git \
106+
gcc-12 \
107+
g++-12 \
108+
build-essential \
109+
ca-certificates \
110+
curl \
111+
--no-install-recommends -y && \
112+
git clone --recursive https://github.com/xmake-io/xmake.git ./xmake && \
113+
cd xmake && \
114+
make build && \
115+
make install && \
116+
cd .. && rm -rf xmake/ && \
117+
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 110 --slave /usr/bin/g++ g++ /usr/bin/g++-12 --slave /usr/bin/gcov gcov /usr/bin/gcov-12 && \
118+
rm -rf /var/lib/apt/lists/*
119+
```
120+
121+
122+
### Step 1 - Building the Multiarch Builder with Buildx
123+
124+
1. First we are going to set up the multi-architecture builder with `docker buildx`:\
125+
`docker buildx create --name str-multiarch --use`
126+
2. And verify that it is loaded:\
127+
`docker buildx inspect --bootstrap`
128+
3. For some reason, buildx can occasionally have a bug where it won't build emulated architectures, but we can get around that with the command:\
129+
`docker run --rm --privileged multiarch/qemu-user-static --reset -p yes`
130+
4. Now we will create the multi-architecture builder for both `linux/amd64` and `linux/arm64` architectures. This will create the builder image for use on PCs with AMD/Intel CPU and also for RaspberryPi/equivalent running x64 Linux:\
131+
`docker buildx build --platform linux/amd64,linux/arm64 -f Dockerfile.builder -t username/multiarch-builder:latest --push .`
132+
133+
This builder image is based off of Ubuntu 22.04 and installs the necessary requirements to build the server docker image later. This step is only required once, since any time you build the server image afterwards your multiarch-builder image can be pulled from Docker Hub.
134+
135+
136+
137+
### Step 2 - Building the Multiarch Server Container with Buildx
138+
139+
1. Since you're following these instructions, I assume you want to pull the `multiarch-builder` we just built from your Docker Hub repository. If that is the case, edit the first line of `Dockerfile` to read:\
140+
`FROM username/multiarch-builder:latest as builder`
141+
2. Now we'll use our multiarch-builder to create the server docker container:\
142+
`docker buildx build --platform linux/amd64,linux/arm64 -f Dockerfile -t username/st-reborn-server:latest --push .`
143+
* If you want to build a specific repository/branch, you can pass `REPO` or `BRANCH` as a `--build-arg`, like so:
144+
`docker buildx build --build-arg BRANCH=master --build-arg REPO=http://github.com/tiltedphoques/TiltedEvolution.git --platform linux/amd64,linux/arm64 -f Dockerfile -t username/st-reborn-server:latest --push .`
145+
146+
This will create a manifest with two containers, one for linux/amd64 (Intel/AMD PCs) and one for linux/arm64 (RaspberryPi/equivalent), and push them to your docker hub. If you want to build only the server for your architecture, you can omit the other one. Alternatively, you could simply `docker build .` to build the server without buildx, but it will only build for your current architecture. As of writing, `docker build .` will only work with linux/amd64 and linux/aarch64 architectures.

guides/server-guide/linux-setup/docker-setup.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,20 @@ I like to put my stuff in `/opt/` so that's what we will do for now
5353
## I want to use docker-compose, what is the template?
5454

5555
```
56-
version: "3.9"
56+
version: "3"
5757
5858
services:
5959
skyrimserver:
6060
container_name: skyrimserver
6161
image: tiltedphoques/st-reborn-server:latest
6262
ports:
63-
- "10578:10578/udp"
63+
- "10578:10578/udp"
6464
volumes:
6565
- /opt/docker/skyrimserver/config:/home/server/config
6666
- /opt/docker/skyrimserver/logs:/home/server/logs
6767
- /opt/docker/skyrimserver/Data:/home/server/Data
68+
- /etc/localtime:/etc/localtime:ro
69+
- /etc/timezone:/etc/timezone:ro
6870
restart: unless-stopped
6971
stdin_open: true
7072
tty: true

0 commit comments

Comments
 (0)