diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e835bb8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +# Build Stage +FROM node:18-alpine AS build + +# Set the working directory +WORKDIR /app + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Install the dependencies +RUN npm install + +# Copy necessary configurations to the working directory +COPY postcss.config.cjs ./ +COPY svelte.config.js ./ +COPY tailwind.config.ts ./ +COPY tsconfig.json ./ +COPY vite.config.ts ./ + +# Copy the source code to the working directory +COPY src ./src +COPY static ./static +# COPY .svelte-kit ./.svelte-kit + +# Build the application +RUN npm run build + +# Production Stage +FROM nginx:alpine + +# Copy the built files from the build stage +COPY --from=build /app/build /usr/share/nginx/html + +# Copy the nginx configuration file +COPY nginx.conf /etc/nginx/conf.d/default.conf + +# Expose the port on which the application will run +EXPOSE 8080 + +# Start nginx server +CMD ["nginx", "-g", "daemon off;"] diff --git a/Dockerfile.dev b/Dockerfile.dev deleted file mode 100644 index 6e250e3..0000000 --- a/Dockerfile.dev +++ /dev/null @@ -1,28 +0,0 @@ -# Build the Svelte application -# Use the official Node.js image as the base image -FROM node:18-alpine - -# Set the working directory -WORKDIR /app - -# Copy package.json and package-lock.json to the working directory -COPY package*.json ./ - -# Install the dependencies -RUN npm install - -# Copy necessary configurations to the working directory -COPY postcss.config.cjs ./ -COPY svelte.config.js ./ -COPY tailwind.config.ts ./ -COPY tsconfig.json ./ -COPY vite.config.ts ./ - -# Copy the source code to the working directory -COPY src ./src -COPY static ./static -COPY .svelte-kit ./.svelte-kit - -EXPOSE 3000 - -CMD ["npm", "run", "dev"] diff --git a/docker-compose.yml b/docker-compose.yml index 9f34208..8a06ebf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,9 +3,9 @@ services: svelte-app: build: context: . - dockerfile: Dockerfile.dev + dockerfile: Dockerfile ports: - - '3000:3000' + - '8080:8080' volumes: - type: bind source: ${JSON_ASSETS_PATH} diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..9b1d50a --- /dev/null +++ b/nginx.conf @@ -0,0 +1,14 @@ +server { + listen 8080; + server_name localhost; + + location / { + root /usr/share/nginx/html; + try_files $uri $uri/ /index.html; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +}