diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c900510..4993041 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,39 +1,40 @@ -name: CI-CD Pipeline +name: Multi-Job Container Pipeline on: push: - branches: [ "main", "feature/*" ] + branches: [ "dev-stable-build" ] # Only runs when we push to this branch pull_request: branches: [ "main" ] jobs: - test-and-deploy: + # JOB 1: The "Inside GitHub" Test + container-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + + - name: Build the Testing Image + run: docker build -t internal-test-image . - # --- STEP 1: UNIT TESTING --- - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.9' - - - name: Install dependencies - run: pip install pytest - - - name: Run Pytest - run: pytest + - name: Run Pytest INSIDE the Container + # This is what the teacher wants: Pytest running in the cloud container + run: docker run --rm internal-test-image pytest - # --- STEP 2: DOCKER HUB DEPLOY (Only on Main Branch) --- + # JOB 2: The Deployment (Only if Job 1 passes) + docker-hub-push: + needs: container-test + runs-on: ubuntu-latest + # This prevents pushing to Docker Hub until we are ready for 'main' + if: github.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v4 - name: Login to Docker Hub - if: github.ref == 'refs/heads/main' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and Push - if: github.ref == 'refs/heads/main' run: | docker build -t skalgleb2devops/testing:latest . docker push skalgleb2devops/testing:latest diff --git a/Dockerfile b/Dockerfile index b68ff85..abcb524 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,14 @@ -# Use the tiny Alpine image -FROM alpine:3.18 +FROM python:3.9-slim -# Install Python and Pytest -RUN apk add --no-cache python3 py3-pip curl && \ - pip install pytest --break-system-packages - -# Set the working directory inside the container WORKDIR /app -# Copy your files from your ThinkPad into the container -COPY app.py test_app.py ./ +# Copy the requirements file first +COPY requirements.txt . + +# Install the "baked-in" tools +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of your code +COPY . . -# This command runs the tests when the container starts -CMD ["pytest"] +CMD ["python", "app.py"] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4649a3c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask +pytest