Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download releases instead #22

Merged
merged 16 commits into from
Jan 14, 2025
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
pull_request:
branches:
- master
- main
push:

jobs:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
1. Python 3.11
2. Poetry (Recommended)
3. Docker (**Strongly** recommended that this is ran in rootless mode)
4. ~10GB of disk space
4. ~1GB of disk space

## About:

Expand Down
19 changes: 9 additions & 10 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS builder
FROM mcr.microsoft.com/dotnet/runtime:9.0-alpine AS builder


RUN adduser odcompile -H -D
RUN apk add libsodium-dev

WORKDIR /opendream

COPY ./OpenDream/ .

ARG BULD_CONFIG=Release

RUN dotnet build OpenDreamServer --configuration ${BULD_CONFIG} && \
dotnet build DMCompiler --configuration ${BULD_CONFIG} && \
ln -s /opendream/bin/DMCompiler/DMCompiler /usr/bin/ && \
ln -s /opendream/bin/Content.Server/OpenDreamServer /usr/bin
RUN ln -s /opendream/DMCompiler_linux-x64/ /opendream/compiler
RUN ln -s /opendream/OpenDreamServer_linux-x64/ /opendream/server

FROM builder

WORKDIR /app

COPY docker/run.sh .

RUN adduser odcompile -H -D && \
chown -R odcompile: /app && \
chown -R odcompile: /opendream/bin
RUN chown -R odcompile: /opendream
RUN chown -R odcompile: /app

USER odcompile

Expand Down
4 changes: 2 additions & 2 deletions docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ cp /app/code/* .
echo "---Preamble---"
echo Included compiler arguments: "$@"
echo "---Start Compiler---"
DMCompiler "$@" test.dme
dotnet exec /opendream/compiler/DMCompiler.dll "$@" test.dme
echo "---End Compiler---"
echo "---Start Server---"
OpenDreamServer --config-file server_config.toml --cvar opendream.json_path=/app/test.json
dotnet exec /opendream/server/Robust.Server.dll --config-file server_config.toml --cvar opendream.json_path=/app/test.json
echo "---End Server---"
71 changes: 68 additions & 3 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ flask = "^2.3"
docker = "^6.0"
gitpython = "^3.1"
gunicorn = "^20.1"
wget = "^3.2"

[tool.poetry.group.dev.dependencies]
flake8 = "^6.0"
Expand Down
4 changes: 2 additions & 2 deletions src/od_compiler/util/docker_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def updateBuildImage(build_config: str) -> None:
"""
od_path = Path.cwd().joinpath("OpenDream")
try:
updateOD(od_repo_path=od_path)
updateOD(od_path=od_path)
except BadName:
compile_logger.warning("There was an error updating the repo. Cleaning up and trying again.")
updateOD(od_repo_path=od_path, clean=True)
updateOD(od_path=od_path, clean=True)

compile_logger.info("Building the docker image...")
client.images.build(
Expand Down
72 changes: 42 additions & 30 deletions src/od_compiler/util/git_actions.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
import os
import tarfile
from pathlib import Path

from git.repo import Repo
import git
import wget
from od_compiler.util.compiler_logger import compile_logger


def updateOD(od_repo_path: Path, clean: int = False) -> None:
def updateOD(od_path: Path, clean: int = False) -> None:
"""
Update the OpenDream repository if it exists. If it doesn't, clone a fresh copy.
"""
if clean:
from shutil import rmtree

rmtree(od_repo_path)

if Path.exists(od_repo_path):
od = Repo(od_repo_path)
od.remote().fetch()
# We reset HEAD to the upstream commit as a faster and more reliable way to stay up to date
od.head.reset(commit="origin/master", working_tree=True)
else:
compile_logger.info("Repo not found. Cloning from GitHub.")
od = Repo.clone_from(
url="https://github.com/OpenDreamProject/OpenDream.git",
to_path=od_repo_path,
multi_options=["--depth 1", "--recurse-submodules", "--shallow-submodules"],
)

compile_logger.info(f"The OpenDream repo is at: {od.head.commit.hexsha}")
updateSubmodules(od_repo=od)

compiler_path = od_path / "compiler.tar.gz"
server_path = od_path / "server.tar.gz"
tag_path = od_path / "tag"

def updateSubmodules(od_repo: Repo) -> None:
"""
Recursively update and initialize submodules
if clean:
from shutil import rmtree

od_repo: OpenDream repository with the submodules
"""
for submodule in od_repo.submodules:
submodule.update(init=True, recursive=True)
compile_logger.info(f"{submodule.name} is at: {submodule.hexsha}")
rmtree(od_path)

if not Path.exists(od_path):
os.mkdir(od_path)
remote_heads = git.cmd.Git().ls_remote("https://github.com/OpenDreamProject/OpenDream/", heads=True)
tag_path.touch(exist_ok=True)
with open(str(tag_path), "r+") as tag:
if tag.readline() == remote_heads:
compile_logger.info("OpenDream is already up to date.")
return
else:
tag.seek(0)
tag.write(remote_heads)

if compiler_path.exists():
os.remove(compiler_path)
if server_path.exists():
os.remove(server_path)
wget.download(
"https://github.com/OpenDreamProject/OpenDream/releases/download/latest/DMCompiler_linux-x64.tar.gz",
str(compiler_path),
)
wget.download(
"https://github.com/OpenDreamProject/OpenDream/releases/download/latest/OpenDreamServer_linux-x64.tar.gz",
str(server_path),
)

with tarfile.open(str(compiler_path), "r:gz") as tar:
tar.extractall(path=od_path)
with tarfile.open(str(server_path), "r:gz") as tar:
tar.extractall(path=od_path)
compile_logger.info(f"The OpenDream repo is at: {remote_heads}")
4 changes: 2 additions & 2 deletions tests/git_actions/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@


def test_update_repo_clean(od_repo_path):
updateOD(od_repo_path=od_repo_path, clean=True)
updateOD(od_path=od_repo_path, clean=True)


@pytest.mark.depends(on=["test_update_repo_clean"])
def test_update_repo_existing(od_repo_path):
updateOD(od_repo_path=od_repo_path)
updateOD(od_path=od_repo_path)