diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..635873b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +**/obj/ +**/bin/ +**/node_modules diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d6c0355 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,69 @@ +FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build + +RUN apk add npm + +WORKDIR /source + +COPY src/Nyanlabs.SFood.UI/sfood/package*.json src/Nyanlabs.SFood.UI/sfood/ + +RUN + +COPY Nyanlabs.SFood.sln ./ + +COPY src/Nyanlabs.SFood.Api/*.csproj ./src/Nyanlabs.SFood.Api/ +COPY src/Nyanlabs.SFood.UI/*.csproj ./src/Nyanlabs.SFood.UI/ +COPY test/Nyanlabs.SFood.Test/*.csproj ./test/Nyanlabs.SFood.Test/ + +RUN dotnet restore + +COPY src/Nyanlabs.SFood.Api/. ./src/Nyanlabs.SFood.Api/ +COPY src/Nyanlabs.SFood.UI/. ./src/Nyanlabs.SFood.UI/ + +RUN dotnet test --no-restore + +RUN dotnet publish ./src/Nyanlabs.SFood.Api/ -c Release -o /build/api +RUN dotnet publish ./src/Nyanlabs.SFood.UI/ -c Release -o /build/ui + +FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS api + +# Files + +COPY --from=build /build/api /srv + +VOLUME [ "/srv/log" ] + +WORKDIR /srv + +ENV ASPNETCORE_ENVIRONMENT=Production + +# Net + +EXPOSE 80/tcp + +# Process handling + +STOPSIGNAL SIGTERM + +ENTRYPOINT [ "dotnet", "/srv/Nyanlabs.SFood.Api.dll" ] + +FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS ui + +# Files + +COPY --from=build /build/ui /srv + +VOLUME [ "/srv/log" ] + +WORKDIR /srv + +ENV ASPNETCORE_ENVIRONMENT=Production + +# Net + +EXPOSE 80/tcp + +# Process handling + +STOPSIGNAL SIGTERM + +ENTRYPOINT [ "dotnet", "/srv/Nyanlabs.SFood.UI.dll" ] diff --git a/dev.Caddyfile b/dev.Caddyfile new file mode 100644 index 0000000..302baf0 --- /dev/null +++ b/dev.Caddyfile @@ -0,0 +1,4 @@ +http://localhost { + reverse_proxy /api/* http://sfood_api:80 + reverse_proxy http://sfood_ui:80 +} diff --git a/dev.Dockerfile b/dev.Dockerfile new file mode 100644 index 0000000..76d493e --- /dev/null +++ b/dev.Dockerfile @@ -0,0 +1,32 @@ +FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine as base + +EXPOSE 80/tcp +EXPOSE 443/tcp + +ENV USERNAME=meowie +ENV USER_UID=1000 +ENV USER_GID=1001 + +RUN addgroup -g $USER_GID $USERNAME \ + && adduser -u $USER_UID -G $USERNAME -D $USERNAME + +RUN mkdir -p /srv/log +RUN chown -R $USERNAME:$USERNAME /srv/log + +VOLUME [ "/srv/log" ] + +STOPSIGNAL SIGKILL + +WORKDIR /source + +FROM base AS api + +USER $USERNAME +ENTRYPOINT [ "dotnet", "watch", "--project", "./src/Nyanlabs.SFood.Api", "run", "--", "--urls", "http://0.0.0.0:80" ] + +FROM base AS ui + +RUN apk add npm + +USER $USERNAME +ENTRYPOINT [ "dotnet", "watch", "--project", "./src/Nyanlabs.SFood.UI", "run", "--", "--urls", "http://0.0.0.0:80" ] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b30a89d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,33 @@ +version: "3" + +services: + ui: + container_name: sfood_ui + image: docker.femsci.net:5000/sfood_ui:dev + build: + context: ./ + dockerfile: dev.Dockerfile + target: ui + volumes: + - ./:/source + environment: + - ASPNETCORE_ENVIRONMENT=Development + api: + container_name: sfood_api + image: docker.femsci.net:5000/sfood_api:dev + build: + context: ./ + dockerfile: dev.Dockerfile + target: api + volumes: + - ./:/source + environment: + - ASPNETCORE_ENVIRONMENT=Development + rp: + container_name: caddy + image: caddy:alpine + ports: + - 80:80 + - 443:443 + volumes: + - ./dev.Caddyfile:/etc/caddy/Caddyfile