Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
prv-proton committed Dec 12, 2024
1 parent 71c2d5b commit 971335b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/docker-auto-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ jobs:
run: |
sed -i 's/: true/: "true"/g; s/: false/: "false"/g' docker-compose.yml
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ github.sha }}
restore-keys: |
${{ runner.os }}-docker-${{ github.ref_name }}
${{ runner.os }}-docker-
- name: Build and start services
run: |
docker-compose build
Expand Down
44 changes: 19 additions & 25 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
# Base stage for common setup
FROM python:3.11-slim-bullseye as base

RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*

RUN pip install poetry==1.6.1

# Configuring poetry
RUN poetry config virtualenvs.create false

# Copying requirements of a project
COPY pyproject.toml poetry.lock /app/
# Install build dependencies and Poetry in one step to minimize layers
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& pip install --no-cache-dir poetry==1.6.1 \
&& poetry config virtualenvs.create false \
&& apt-get purge -y gcc \
&& rm -rf /var/lib/apt/lists/*

# Set work directory
WORKDIR /app

# Installing requirements
RUN poetry install --only main
# Copy only dependency files first (to leverage caching)
COPY pyproject.toml poetry.lock /app/

# Removing gcc
RUN apt-get purge -y \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Install only main dependencies
RUN poetry install --only main --no-root

# Copying the actual application, wait-for-it script, and prestart script
# Copy the rest of the application files
COPY . /app/

# Note: We mount the local directory using docker-compose so ensure these scripts also have execute permissions
# by running the following command on your host machine from the root of this project:
# chmod +x ./backend/wait-for-it.sh ./backend/lcfs/prestart.sh ./backend/lcfs/start.sh ./backend/lcfs/start-reload.sh

# Make all startup scripts executable
# Make necessary scripts executable
RUN chmod +x /app/wait-for-it.sh /app/lcfs/prestart.sh /app/lcfs/start.sh

CMD /bin/bash /app/lcfs/start.sh
# Default startup command
CMD ["/bin/bash", "/app/lcfs/start.sh"]

# Production stage
FROM base as prod
Expand All @@ -43,5 +36,6 @@ ENV APP_ENVIRONMENT=prod
FROM base as dev
# Set the APP_ENVIRONMENT variable to 'development'
ENV APP_ENVIRONMENT=dev

# Install additional dependencies for development
RUN poetry install
RUN poetry install --no-root

0 comments on commit 971335b

Please sign in to comment.