From d4bb3c30b5cba5377b25a1c2b4589c290fa854cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ch=C4=99ci=C5=84ski?= Date: Wed, 7 Dec 2022 09:51:25 +0100 Subject: [PATCH] Create Dockerfile for Billing (#2477) * build script for billing * Add entrypoint script * Add dockerfile and docker ignore --- src/Billing/.dockerignore | 4 ++++ src/Billing/Dockerfile | 21 ++++++++++++++++++++ src/Billing/build.sh | 14 +++++++++++++ src/Billing/entrypoint.sh | 41 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 src/Billing/.dockerignore create mode 100644 src/Billing/Dockerfile create mode 100755 src/Billing/build.sh create mode 100644 src/Billing/entrypoint.sh diff --git a/src/Billing/.dockerignore b/src/Billing/.dockerignore new file mode 100644 index 000000000..fc12f2514 --- /dev/null +++ b/src/Billing/.dockerignore @@ -0,0 +1,4 @@ +* +!obj/build-output/publish/* +!obj/Docker/empty/ +!entrypoint.sh diff --git a/src/Billing/Dockerfile b/src/Billing/Dockerfile new file mode 100644 index 000000000..cd00c068f --- /dev/null +++ b/src/Billing/Dockerfile @@ -0,0 +1,21 @@ +FROM mcr.microsoft.com/dotnet/aspnet:6.0 + +LABEL com.bitwarden.product="bitwarden" + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + gosu \ + curl \ + && rm -rf /var/lib/apt/lists/* + +ENV ASPNETCORE_URLS http://+:5000 +WORKDIR /app +EXPOSE 5000 +COPY entrypoint.sh / +RUN chmod +x /entrypoint.sh + +COPY obj/build-output/publish . + +HEALTHCHECK CMD curl -f http://localhost:5000/alive || exit 1 + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/src/Billing/build.sh b/src/Billing/build.sh new file mode 100755 index 000000000..85b3fd8ba --- /dev/null +++ b/src/Billing/build.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +echo -e "\n## Building Billing" + +echo -e "\nBuilding app" +echo -e ".NET Core version $(dotnet --version)" +echo -e "Restore" +dotnet restore $DIR/Billing.csproj +echo -e "Clean" +dotnet clean $DIR/Billing.csproj -c "Release" -o $DIR/obj/build-output/publish +echo -e "Publish" +dotnet publish $DIR/Billing.csproj -c "Release" -o $DIR/obj/build-output/publish diff --git a/src/Billing/entrypoint.sh b/src/Billing/entrypoint.sh new file mode 100644 index 000000000..5fb0c5c67 --- /dev/null +++ b/src/Billing/entrypoint.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Setup + +GROUPNAME="bitwarden" +USERNAME="bitwarden" + +LUID=${LOCAL_UID:-0} +LGID=${LOCAL_GID:-0} + +# Step down from host root to well-known nobody/nogroup user + +if [ $LUID -eq 0 ] +then + LUID=65534 +fi +if [ $LGID -eq 0 ] +then + LGID=65534 +fi + +# Create user and group + +groupadd -o -g $LGID $GROUPNAME >/dev/null 2>&1 || +groupmod -o -g $LGID $GROUPNAME >/dev/null 2>&1 +useradd -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1 || +usermod -o -u $LUID -g $GROUPNAME -s /bin/false $USERNAME >/dev/null 2>&1 +mkhomedir_helper $USERNAME + +# The rest... + +chown -R $USERNAME:$GROUPNAME /app +mkdir -p /etc/bitwarden/core +mkdir -p /etc/bitwarden/logs +mkdir -p /etc/bitwarden/ca-certificates +chown -R $USERNAME:$GROUPNAME /etc/bitwarden + +cp /etc/bitwarden/ca-certificates/*.crt /usr/local/share/ca-certificates/ >/dev/null 2>&1 \ + && update-ca-certificates + +exec gosu $USERNAME:$GROUPNAME dotnet /app/Billing.dll