Skip to content

Commit

Permalink
chore: 🤖 rewrite docker file
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanonymous-GitHub committed May 2, 2023
1 parent da2ef9c commit 2a4d96b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LICENSE
README.md
sonar-project.properties
setup.py
.github
62 changes: 52 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,59 @@
FROM python:alpine
# Use an official Python runtime as a parent image
FROM python:alpine AS base

ARG PORT=7777
ARG HOST='0.0.0.0'
# Set up a non-root user and working directory
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
WORKDIR /app

ENV PORT=$PORT
ENV HOST=$HOST
# Copy only the necessary files for dependency installation
COPY requirements.txt .

COPY . /heyptt
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt --no-cache-dir

WORKDIR /heyptt
# Use multistage build to create a separate build stage
FROM base AS builder

RUN pip3 install -r ./requirements.txt --upgrade --no-cache-dir
# Copy the rest of the application code
COPY --chown=appuser:appgroup . .

EXPOSE $PORT
# New stage for building the web assets
FROM node:lts-alpine AS web_builder

CMD ["python3", "serve.py"]
# Initialize pnpm globally
RUN corepack enable

# Set up a non-root user and working directory for the web project
RUN addgroup -S webgroup && adduser -S webuser -G webgroup
USER webuser
WORKDIR /web

# Copy the package.json and pnpm-lock.yaml files for dependency installation
COPY --chown=webuser:webgroup web/package.json web/pnpm-lock.yaml ./

# Install the web project dependencies
RUN pnpm install --frozen-lockfile

# Copy the rest of the web project files
COPY --chown=webuser:webgroup web/ .

# Build the web project
RUN pnpm build

# Switch back to the base image
FROM base

# Copy the compiled application from the builder stage
COPY --from=builder --chown=appuser:appgroup /app /app

# Copy the built web assets to /website
COPY --from=web_builder --chown=appuser:appgroup /web/dist /app/website

# Set the environment variables
ENV PORT=${PORT}
ENV HOST=${HOST:-0.0.0.0}

# Make the container executable and run the application
ENTRYPOINT ["python3"]
CMD ["serve.py"]
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
version: '3'

services:
heyptt:
hey-ptt:
build:
context: .
dockerfile: ./Dockerfile
image: hey-ptt
ports:
- '7777:7777'
environment:
- PORT=7777
- HOST=0.0.0.0
restart: unless-stopped

0 comments on commit 2a4d96b

Please sign in to comment.