From ca5609008229cdd1334a63ecf53c12add8a13918 Mon Sep 17 00:00:00 2001 From: monstera-brm Date: Sun, 3 Aug 2025 17:59:01 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=C3=A4dd=20gh=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-build.yml | 53 ++++++++++++++++++++++++++++++ Dockerfile | 14 ++++++++ compose.yaml | 11 +++++++ 3 files changed, 78 insertions(+) create mode 100644 .github/workflows/docker-build.yml create mode 100644 Dockerfile create mode 100644 compose.yaml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..30d68aa --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,53 @@ +name: Build and Push Docker Image + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=sha,prefix={{branch}}- + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..92a5e40 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM python:3.12-slim + +# Set working directory +WORKDIR /app + +# Copy requirements first for better caching (if you have any) +# COPY requirements.txt . +# RUN pip install --no-cache-dir -r requirements.txt + +# Copy application code +COPY main.py . + +# Default command: run the Python application +CMD [ "python", "main.py" ] \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..8e1c032 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,11 @@ +services: + test_deployment: + build: . + image: test_deployment:latest + container_name: test_deployment + volumes: + - .:/workspace + tty: true + working_dir: /workspace + command: ["bash"] + # Uncomment the following line if you want to run a specific command on startup \ No newline at end of file From 0bfa2cd02465d2303949271ab4eacb0e755ef5df Mon Sep 17 00:00:00 2001 From: monstera-brm Date: Sun, 3 Aug 2025 18:00:56 +0200 Subject: [PATCH 2/2] fix tag --- .github/workflows/docker-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 30d68aa..95329e9 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -39,7 +39,7 @@ jobs: tags: | type=ref,event=branch type=ref,event=pr - type=sha,prefix={{branch}}- + type=sha,prefix=sha- type=raw,value=latest,enable={{is_default_branch}} - name: Build and push Docker image