Skip to content

Commit

Permalink
Add Dockerfile and docker composer to project (#615)
Browse files Browse the repository at this point in the history
* feat: initial docker file to webapi project

* feat: try crete docker files

* Fix Dockerfile

* 🆙: update dockerfile to running correctly.

* feat: adjustments on docker compose

---------

Co-authored-by: Felipe Muniz <felipemuniznet@gmail.com>
Co-authored-by: MarcusViniciusS <lowpoc.developer@gmail.com>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 8b1e5e2 commit bc8b086
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 25 deletions.
50 changes: 38 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
# PostgreSQL: https://hub.docker.com/_/postgres/
postgres-compose:
postgres:
image: postgres
container_name: postgres
environment:
Expand All @@ -12,10 +12,10 @@ services:
volumes:
- postgresql-data:/var/lib/postgresql/data
networks:
- postgres
- opencoremmo

# pgAdmin 4: https://hub.docker.com/r/dpage/pgadmin4
pgadmin-compose:
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin4
environment:
Expand All @@ -24,9 +24,9 @@ services:
ports:
- "8080:80"
depends_on:
- postgres-compose
networks:
- postgres
networks:
- opencoremmo
volumes:
- ./docker/pgadmin-servers.json:/pgadmin4/servers.json
- pgadmin-data:/var/lib/pgadmin
Expand All @@ -39,7 +39,7 @@ services:
- "27017:27017"
restart: "on-failure"
networks:
- graylog
- opencoremmo
volumes:
- "mongodb-data:/data/db"
- "mongodb-config:/data/configdb"
Expand All @@ -66,7 +66,7 @@ services:
- "9200:9200/tcp"
- "9300:9300/tcp"
networks:
- graylog
- opencoremmo
volumes:
- "graylog-datanode:/var/lib/graylog-datanode"
restart: "on-failure"
Expand Down Expand Up @@ -112,14 +112,40 @@ services:
- "13302:13302/tcp"
restart: "on-failure"
networks:
- graylog
- opencoremmo
volumes:
- "graylog-data:/usr/share/graylog/data"

# OpenCoreMMO
standalone:
container_name: standalone
build:
context: .
dockerfile: ./src/Standalone/Dockerfile
environment:
ASPNETCORE_ENVIRONMENT: "Production"
ports:
- "7171:7171"
- "7172:7172"
networks:
- opencoremmo
depends_on:
- postgres

# webapi-compose:
# container_name: webapi
# build:
# context: ./src/WebAPI/
# dockerfile: Dockerfile
# environment:
# ASPNETCORE_ENVIRONMENT: "Production"
# ports:
# - "80:80"
# networks:
# - opencoremmo

networks:
postgres:
driver: bridge
graylog:
opencoremmo:
driver: bridge

volumes:
Expand All @@ -128,4 +154,4 @@ volumes:
mongodb-data:
mongodb-config:
graylog-datanode:
graylog-data:
graylog-data:
2 changes: 1 addition & 1 deletion docker/pgadmin-servers.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"1": {
"Name": "Postgres Server",
"Group": "Servers",
"Host": "postgres-compose",
"Host": "postgres",
"Port": 5432,
"Username": "postgres",
"SSLMode": "prefer",
Expand Down
25 changes: 25 additions & 0 deletions src/Standalone/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
38 changes: 38 additions & 0 deletions src/Standalone/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Use an official .NET 9 SDK as a parent image
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build

# Set the working directory to /app
WORKDIR /app

COPY data/. ./out/data

# Copy the project files to the container
COPY src/. .

# Remove any bin or obj folders to ensure a clean build
RUN find . -type d \( -name "bin" -o -name "obj" \) -exec rm -rf {} +

# Restore dependencies
RUN dotnet restore Standalone/NeoServer.Server.Standalone.csproj

# Restore dependencies
RUN dotnet restore out/data/extensions/NeoServer.Extensions.csproj

# Build the project
RUN dotnet publish Standalone/NeoServer.Server.Standalone.csproj -c Release -o out

# Use an official .NET 9 runtime as a parent image
FROM mcr.microsoft.com/dotnet/runtime:9.0

# Set the working directory to /app
WORKDIR /app

# Copy the published app to the container
COPY --from=build /app/out .

# Expose the ports that the server will listen on
EXPOSE 7171
EXPOSE 7172

# Set the entrypoint to run the console app
ENTRYPOINT ["dotnet", "NeoServer.Server.Standalone.dll"]
25 changes: 25 additions & 0 deletions src/WebAPI/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
20 changes: 8 additions & 12 deletions src/WebAPI/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG ASPNET_VERSION="7.0.2"
ARG SDK_VERSION="7.0.102"
ARG ASPNET_VERSION="9.0"
ARG SDK_VERSION="9.0"
ARG BASE_ADRESS="mcr.microsoft.com/dotnet"

FROM $BASE_ADRESS/aspnet:$ASPNET_VERSION AS base
Expand All @@ -9,23 +9,19 @@ EXPOSE 80

FROM $BASE_ADRESS/sdk:$SDK_VERSION AS build

COPY ./global.json ./
COPY ./nuget.config ./
COPY ./Directory.Build.props ./

WORKDIR /src

COPY *.csproj ./AdminAPI
COPY *.csproj ./WebAPI

RUN dotnet restore -v m ./AdminAPI
RUN dotnet restore -v m ./WebAPI

WORKDIR /src/AdminAPI
RUN dotnet build -c Release --no-restore -v m -o /app/build
WORKDIR /src/WebAPI
RUN dotnet build NeoServer.Web.API.csproj -c Release -o /app/build --no-restore

FROM build AS publish
RUN dotnet publish -c Release --no-restore -v m -o /app/publish
RUN dotnet publish NeoServer.Web.API.csproj -c Release -o /app/publish --no-restore

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "NeoServer.API.dll"]
ENTRYPOINT ["dotnet", "NeoServer.Web.API.dll"]

0 comments on commit bc8b086

Please sign in to comment.