Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/appsettings.Development.json
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it also include the stuff in .gitignore?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think it does. Should copy the same things to this file.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it needs the whole gitignore, but it should exclude appsettings.Local.json.

29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 as builder

COPY . /ModShark
WORKDIR /ModShark

RUN dotnet publish ModShark.sln


FROM mcr.microsoft.com/dotnet/runtime:8.0

# Install jq and use Docker caching for package downloads
ENV DEBIAN_FRONTEND=noninteractive
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
rm -rf /etc/apt/apt.conf.d/docker-clean && \
apt-get update && apt-get install -y jq

# Add modshark user and copy built modshark
RUN useradd -m -s /bin/bash modshark
COPY --from=builder --chown=modshark:modshark /ModShark/ModShark/bin/Release/net8.0/publish/ /ModShark
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it helps, there's now a /Resources/build-prod.ps1 script that runs a build and stages all the compiled output in a predictable /Publish directory. You can copy the whole thing as-is or just take parts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Will try to take a look and possibly use that.

COPY --from=builder --chown=modshark:modshark /ModShark/SharkeyDB/bin/Release/net8.0/publish/ /SharkeyDB
COPY --from=builder --chown=modshark:modshark /ModShark/entrypoint.sh /entrypoint.sh

USER modshark
WORKDIR /ModShark

# Start ModShark at container startup
ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "dotnet", "/ModShark/ModShark.dll" ]
21 changes: 21 additions & 0 deletions entrypoint.sh
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModShark requires database migrations upon installation and then with each update. They're meant to be run manually by a DBA / admin, but they could be bundled and run on startup.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
if [[ $# > 0 ]]; then
tmpfile=$(mktemp)
vars=()
while IFS='=' read -r -d '' n v; do
if [[ $n == "MODSHARK__"* ]]; then
vars+=("$(printf "%s=%s" "$n" "$v")")
fi
done < <(env -0)

for var in "${vars[@]}"; do
item=$(echo "${var}" | grep ^MODSHARK__ | sed s/^MODSHARK__/./g | sed s/__/./g)
key=$(echo "${item}" | cut -d "=" -f 1)
value=$(echo "${item}" | cut -d "=" -f 2-)
jq $key="\"$value\"" appsettings.json > $tmpfile && \
mv $tmpfile appsettings.json
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appsettings.json should not be modified, as it's meant to be a template of default values. Instead, user settings / overrides should go in appsettings.Production.json. The application will overlay the configurations, with Production getting priority.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. WIll fix.

done
exec $@
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to set DOTNET_ENVIRONMENT=Production before running

else
/bin/bash
fi