diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..95329e9 --- /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=sha- + 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