Skip to content

Commit

Permalink
update build process
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicTheDev committed Dec 17, 2024
1 parent 43f640f commit 35ef69b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,45 @@ jobs:
runs-on: ubuntu-latest

steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }} # Automatically checkout the triggering branch

# Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Cache Docker layers
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}

# Sanitize branch name for tagging
- name: Sanitize branch name
id: sanitize
run: echo "SANITIZED_BRANCH=$(echo '${{ github.ref_name }}' | sed 's/[^a-zA-Z0-9_.-]/-/g')" >> $GITHUB_ENV

# Build and push Docker image with caching
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: |
ghcr.io/clashkinginc/clashkingbot:${{ github.ref_name == 'master' && 'latest' || env.SANITIZED_BRANCH }}
26 changes: 17 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
# Use an updated Python image
FROM python:3.11-bookworm
# Stage 1: Base Image with Python and System Dependencies
FROM python:3.11-bookworm AS base

LABEL org.opencontainers.image.source=https://github.com/ClashKingInc/ClashKingBot
LABEL org.opencontainers.image.description="Image for the ClashKing Discord Bot"
LABEL org.opencontainers.image.licenses=MIT

# Install dependencies
RUN apt-get update && apt-get install -y libsnappy-dev
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends libsnappy-dev && \
rm -rf /var/lib/apt/lists/*

# Set the working directory in the container
# Set the working directory
WORKDIR /app

# First, copy only the requirements.txt file
# Stage 2: Install Python Dependencies
FROM base AS dependencies

# Copy only requirements to leverage Docker cache
COPY requirements.txt .

# Install any needed packages specified in requirements.txt
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Now copy the rest of the application code into the container
# Stage 3: Copy Application Code
FROM dependencies AS final

# Copy the rest of the application code
COPY . .

# Command to run the application
# Set the default command
CMD ["python3", "main.py"]

0 comments on commit 35ef69b

Please sign in to comment.