diff --git a/.gitignore b/.gitignore index 8dd04fe..9e6c2cc 100644 --- a/.gitignore +++ b/.gitignore @@ -22,8 +22,4 @@ settings.json .env.production # macOS-specific files -.DS_Store - -#Docker Ignore -Dockerfile -docker-compose.yml \ No newline at end of file +.DS_Store \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2f8a522 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# Stage 1: Clone the repository and build the Astro project +FROM node:lts-alpine AS build +WORKDIR /app + +# Install git and clone the repository +RUN apk add --no-cache git +ARG REPO_URL +RUN git clone $REPO_URL . + +# Install dependencies and build the project +RUN npm install +RUN npm run build + +# Stage 2: Serve the built application with a lightweight runtime image +FROM node:lts-alpine AS runtime +WORKDIR /app + +# Copy only the necessary files from the build stage +COPY --from=build /app/dist ./dist +COPY --from=build /app/node_modules ./node_modules +COPY --from=build /app/package.json . + +# Set environment variables for the server +ENV HOST=0.0.0.0 +ENV PORT=4321 + +# Expose the port the Astro app runs on +EXPOSE 4321 + +# Command to run the application +CMD ["node", "./dist/server/entry.mjs"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0b4edb5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + astro-app: + build: + context: . + dockerfile: Dockerfile + ports: + - "4321:4321" + volumes: + - .:/app \ No newline at end of file