/
Dockerfile
61 lines (47 loc) · 1.47 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
## Build dotnet app
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS dotnet-build
WORKDIR /app
COPY ./backend/ ./
COPY ./backend_structs/ ./
COPY ./backend_extapi/ ./
# Run restore
RUN dotnet restore --interactive
# Build app
RUN dotnet build --configuration Release
RUN dotnet publish --configuration Release --no-build --output out
# Install dotnet EF tools, set path to run them and create migrations
# SQL script. We need to set the POSTGRES_{x} variables for dotnet ef
# to work (due to our code), we set them to dummies since they are not
# used
RUN dotnet tool install --global dotnet-ef
ENV PATH="/root/.dotnet/tools:${PATH}"
ENV POSTGRES_HOST=x \
POSTGRES_PORT=x \
POSTGRES_DB=x \
POSTGRES_USER=x \
POSTGRES_PASSWORD=x
RUN dotnet ef migrations script --idempotent --output out/migrations.sql
## Build frontend
FROM node:14-alpine3.16 AS node-build
WORKDIR /frontend
COPY ./frontend ./
# Run npm
ARG DOMAIN=localhost:8000
ENV REACT_APP_DOMAIN=$DOMAIN
ENV REACT_APP_SERVICE_NAME=CompetenceHub
ENV REACT_APP_GQL_URL=/graphql
RUN npm install
RUN npm run build
## Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
# In order to run migrations, we need psql
RUN apt-get update && apt-get install -y postgresql-client
# Copy artifacts from previous steps to this image
WORKDIR /app
COPY ./wwwroot /wwwroot/
COPY ./devzone /devzone/
COPY --from=dotnet-build /app/out .
COPY --from=node-build /frontend/build /wwwroot/
COPY ./run.sh .
EXPOSE 8000
CMD ["./run.sh"]