mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
V3 docker
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
!src/NadekoBot.Generators/**
|
!src/NadekoBot.Generators/**
|
||||||
# Use Ayu stuff
|
# Use Ayu stuff
|
||||||
!src/ayu/**
|
!src/ayu/**
|
||||||
|
!docker-entrypoint.sh
|
||||||
|
|
||||||
# ignore bin and obj folders in projects
|
# ignore bin and obj folders in projects
|
||||||
src/**/bin/*
|
src/**/bin/*
|
||||||
|
@@ -96,3 +96,30 @@ upload-windows-updater-release:
|
|||||||
- aws --version
|
- aws --version
|
||||||
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/$INSTALLER_FILE_NAME" --acl public-read --body "$INSTALLER_OUTPUT_DIR/$INSTALLER_FILE_NAME"
|
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/$INSTALLER_FILE_NAME" --acl public-read --body "$INSTALLER_OUTPUT_DIR/$INSTALLER_FILE_NAME"
|
||||||
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/releases-v3.json" --acl public-read --body "releases-v3.json"
|
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/releases-v3.json" --acl public-read --body "releases-v3.json"
|
||||||
|
|
||||||
|
docker-build:
|
||||||
|
# Use the official docker image.
|
||||||
|
image: docker:latest
|
||||||
|
stage: build
|
||||||
|
services:
|
||||||
|
- docker:dind
|
||||||
|
before_script:
|
||||||
|
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||||
|
# Default branch leaves tag empty (= latest tag)
|
||||||
|
# All other branches are tagged with the escaped branch name (commit ref slug)
|
||||||
|
script:
|
||||||
|
- |
|
||||||
|
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
|
||||||
|
tag=""
|
||||||
|
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
|
||||||
|
else
|
||||||
|
tag=":$CI_COMMIT_REF_SLUG"
|
||||||
|
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
|
||||||
|
fi
|
||||||
|
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
|
||||||
|
- docker push "$CI_REGISTRY_IMAGE${tag}"
|
||||||
|
# Run this job in a branch where a Dockerfile exists
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH
|
||||||
|
exists:
|
||||||
|
- Dockerfile
|
||||||
|
35
Dockerfile
35
Dockerfile
@@ -1,4 +1,4 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
|
||||||
WORKDIR /source
|
WORKDIR /source
|
||||||
|
|
||||||
COPY src/NadekoBot/*.csproj src/NadekoBot/
|
COPY src/NadekoBot/*.csproj src/NadekoBot/
|
||||||
@@ -9,14 +9,33 @@ RUN dotnet restore src/NadekoBot/
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
WORKDIR /source/src/NadekoBot
|
WORKDIR /source/src/NadekoBot
|
||||||
RUN dotnet --version
|
RUN set -xe; \
|
||||||
RUN dotnet publish -c Release -o /app --no-restore
|
dotnet --version; \
|
||||||
|
dotnet publish -c Release -o /app --no-restore; \
|
||||||
|
mv /app/data /app/data_init; \
|
||||||
|
rm -Rf libopus* libsodium* opus.* runtimes/win* runtimes/osx* runtimes/linux-arm* runtimes/linux-mips*; \
|
||||||
|
find /app -type f -exec chmod -x {} \; ;\
|
||||||
|
chmod +x /app/NadekoBot
|
||||||
|
|
||||||
# final stage/image
|
# final stage/image
|
||||||
FROM mcr.microsoft.com/dotnet/runtime:5.0
|
FROM mcr.microsoft.com/dotnet/runtime:5.0-buster-slim
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN set -xe; \
|
||||||
|
useradd -m nadeko; \
|
||||||
|
apt-get update; \
|
||||||
|
apt-get install -y libopus0 libsodium23 libsqlite3-0 curl ffmpeg python3 sudo; \
|
||||||
|
update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1; \
|
||||||
|
echo 'Defaults>nadeko env_keep+="ASPNETCORE_* DOTNET_* NadekoBot_* shard_id total_shards TZ"' > /etc/sudoers.d/nadeko; \
|
||||||
|
curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl; \
|
||||||
|
chmod +x /usr/local/bin/youtube-dl
|
||||||
|
|
||||||
|
COPY --from=build /app ./
|
||||||
|
COPY docker-entrypoint.sh /usr/local/sbin
|
||||||
|
|
||||||
ENV shard_id=0
|
ENV shard_id=0
|
||||||
ENV total_shards=1
|
ENV total_shards=1
|
||||||
WORKDIR /app
|
|
||||||
COPY --from=build /app ./
|
VOLUME [ "app/data" ]
|
||||||
VOLUME [ "app/data", "app/creds.yml", "app/creds_example.yml" ]
|
ENTRYPOINT [ "/usr/local/sbin/docker-entrypoint.sh" ]
|
||||||
ENTRYPOINT dotnet NadekoBot.dll "$shard_id" "$total_shards"
|
CMD dotnet NadekoBot.dll "$shard_id" "$total_shards"
|
20
docker-entrypoint.sh
Executable file
20
docker-entrypoint.sh
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e;
|
||||||
|
|
||||||
|
data_init=/app/data_init
|
||||||
|
data=/app/data
|
||||||
|
|
||||||
|
# populate /app/data if empty
|
||||||
|
for i in $(ls $data_init)
|
||||||
|
do
|
||||||
|
if [ ! -e "$data/$i" ]; then
|
||||||
|
[ -f "$data_init/$i" ] && cp "$data_init/$i" "$data/$i"
|
||||||
|
[ -d "$data_init/$i" ] && cp -r "$data_init/$i" "$data/$i"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# fix folder permissions
|
||||||
|
chown -R nadeko:nadeko "$data"
|
||||||
|
|
||||||
|
# drop to regular user and launch command
|
||||||
|
exec sudo -u nadeko "$@"
|
Reference in New Issue
Block a user