Skip to content

Commit

Permalink
Making monorepo with api
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwizi committed May 14, 2024
1 parent c2d5741 commit 3017428
Show file tree
Hide file tree
Showing 344 changed files with 69,741 additions and 72 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/docker-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish API Docker Image

on:
push:
branches:
- monorepo
paths:
- 'api/**'

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest

steps:
- name: Check out the repo
uses: actions/checkout@v4.1.1
- name: Check for changes
id: check_changes
run: |
if [[ $(git diff --name-only ${{ github.event.before }} ${{ github.sha }}) == *"api"* ]]; then
echo "::set-output name=changes::true"
else
echo "::set-output name=changes::false"
fi
- name: Extract version from pyproject.toml
if: steps.check_changes.outputs.changes == 'true'
id: extract_metadata
run: |
VERSION=$(awk -F ' = ' '/version =/ {gsub(/"/, "", $2); print $2}' api/pyproject.toml)
LABELS="version=$VERSION,latest"
echo "::set-output name=version::$VERSION"
echo "::set-output name=labels::$LABELS"
- name: Log in to Docker Hub
if: steps.check_changes.outputs.changes == 'true'
uses: docker/login-action@v3.0.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v5.1.0
if: steps.check_changes.outputs.changes == 'true'
with:
context: ./api
file: ./api/Dockerfile
push: true
tags: ${{ github.repository }}-api-test:${{ steps.extract_metadata.outputs.version }}, ${{ github.repository }}:latest
labels: ${{ steps.extract_metadata.outputs.labels }}
49 changes: 49 additions & 0 deletions .github/workflows/docker-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Publish Bot Docker Image

on:
push:
branches:
- monorepo
paths:
- 'src/**'

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest

steps:
- name: Check out the repo
uses: actions/checkout@v4.1.1
- name: Check for changes
id: check_changes
run: |
if [[ $(git diff --name-only ${{ github.event.before }} ${{ github.sha }}) == *"src"* ]]; then
echo "::set-output name=changes::true"
else
echo "::set-output name=changes::false"
fi
- name: Extract metadata (tags, labels) for Docker
if: steps.check_changes.outputs.changes == 'true'
id: meta
uses: docker/metadata-action@v5.5.1
with:
images: qwizii/cs2-battle-bot-test

- name: Log in to Docker Hub
if: steps.check_changes.outputs.changes == 'true'
uses: docker/login-action@v3.0.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v5.1.0
if: steps.check_changes.outputs.changes == 'true'
with:
context: ./src
file: ./src/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
36 changes: 0 additions & 36 deletions .github/workflows/docker.yml

This file was deleted.

50 changes: 50 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Stage 1: Install Rust, build dependencies, and prepare the build environment
FROM python:3.11.6-slim AS builder

WORKDIR /code


# Install or upgrade pip and Poetry
RUN pip install --upgrade pip && pip install --no-cache-dir --upgrade poetry

# Disable Poetry virtualenv creation
RUN poetry config installer.max-workers 10
RUN poetry config virtualenvs.create false
#RUN poetry config installer.no-binary cryptography

# Copy the project files for dependency installation
COPY ./pyproject.toml ./poetry.lock /code/

# Install project dependencies using Poetry
RUN poetry install --no-interaction --no-ansi



# Stage 2: Runtime environment
FROM builder AS runtime
ENV PYTHONUNBUFFERED 1

# Create a dedicated user for running the application
RUN addgroup --system fastapi && adduser --system --ingroup fastapi fastapiuser

# Set the working directory
WORKDIR /app

# Copy only the necessary files from the build stage
COPY --from=builder /code /app

COPY --from=builder /code/pyproject.toml /app/


# Copy the source code
COPY src /app/


# Change ownership to the dedicated user
RUN chown -R fastapiuser:fastapi /app

# Set the PORT environment variable (customize as needed)
ENV PORT 80

# Switch to the dedicated user
USER fastapiuser
Loading

0 comments on commit 3017428

Please sign in to comment.