diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..9b495245 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +node_modules +Dockerfile* +docker-compose* +.dockerignore +.git +.gitignore +README.md +LICENSE +.vscode +Makefile +helm-charts +.env +.editorconfig +.idea +coverage* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a6532da9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,60 @@ +FROM node:18 AS base +WORKDIR /app + +# Copy package.json and bun.lockb +COPY package.json . +COPY bun.lockb . + +# Install Bun +RUN curl -fsSL https://bun.sh/install | bash + +# Add Bun to PATH +ENV BUN_INSTALL="/root/.bun" +ENV PATH="$BUN_INSTALL/bin:$PATH" + +# Install dependencies using Bun +RUN bun install --frozen-lockfile +RUN npm install -g @angular/cli +RUN bun install + +# --- DEVELOPMENT STAGE --- + +FROM base AS development +ENV NODE_ENV=development + +COPY . /app + +EXPOSE 4200 + +# Run the app in development mode using ng serve +CMD ["bun", "run", "start"] + +# --- BUILD STAGE --- +FROM base AS build + +# Copy all files for the build +COPY . /app + +RUN ng build --configuration ComputasProd + +RUN apt update && apt install -y nginx && \ + rm -rf /var/lib/apt/lists/* + +# --- PRODUCTION STAGE --- +FROM nginx:alpine AS production +ENV NODE_ENV=production + +# Copy the source code for building the production build +COPY . /app + +# Copy built files from the build stage to the Nginx html directory +COPY --from=build /app/dist/tekniskmuseum /usr/share/nginx/html + +# Copy the custom Nginx configuration +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# Expose the Nginx port +EXPOSE 80 + +# Start Nginx +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..343b0d6b --- /dev/null +++ b/nginx.conf @@ -0,0 +1,16 @@ +server { + listen 80; + + server_name localhost; + + root /usr/share/nginx/html; + + location / { + try_files $uri $uri/ /index.html; + } + + location /assets/ { + + try_files $uri $uri/ /index.html; + } +} diff --git a/package.json b/package.json index d62074ff..304e74e4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "version": "0.0.0", "scripts": { "prettier": "prettier --end-of-line=crlf --write src/**/*.ts", - "start": "ng serve", + "start": "ng serve --host 0.0.0.0", "build": "ng build", "build:ci": "ng build --configuration production", "build:computas": "ng build --configuration computas",