Bird
Raised Fist0
Flaskframework~20 mins

CI/CD pipeline for Flask - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Flask CI/CD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a GitHub Actions workflow step for Flask testing
Given this GitHub Actions step that runs Flask tests, what is the output if all tests pass?
      - name: Run tests
        run: |
          python -m venv venv
          source venv/bin/activate
          pip install -r requirements.txt
          pytest tests/
AAll tests passed successfully with no errors.
BSyntaxError: invalid syntax in requirements.txt
CModuleNotFoundError: No module named 'pytest'
DTests failed with assertion errors.
Attempts:
2 left
💡 Hint
Think about what happens when pytest runs and all tests pass.
❓ Configuration
intermediate
2:00remaining
Correct Dockerfile for a Flask app in CI/CD
Which Dockerfile configuration correctly builds a Flask app image for deployment in a CI/CD pipeline?
A
FROM python:3.12-slim
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
B
FROM node:18
WORKDIR /app
COPY . /app
RUN npm install
CMD ["node", "app.js"]
C
FROM python:3.12
COPY requirements.txt /
RUN pip install -r /requirements.txt
COPY . /app
WORKDIR /app
CMD ["flask", "run"]
D
FROM python:3.12
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD ["flask", "run", "--host=0.0.0.0"]
Attempts:
2 left
💡 Hint
Flask apps need to listen on all interfaces in containers.
🔀 Workflow
advanced
2:00remaining
Order of steps in a CI/CD pipeline for Flask
Arrange these steps in the correct order for a typical CI/CD pipeline for a Flask app:
A1,2,3,4
B2,1,3,4
C1,3,2,4
D3,2,1,4
Attempts:
2 left
💡 Hint
Tests must pass before building and pushing images.
❓ Troubleshoot
advanced
2:00remaining
Error when deploying Flask app: "Address already in use"
You deployed your Flask app in a container but get the error: "OSError: [Errno 98] Address already in use". What is the most likely cause?
AThe Dockerfile is missing the requirements.txt file.
BThe Flask app is trying to bind to a port already used by another process.
CThe Flask app code has a syntax error.
DThe container image was not pushed to the registry.
Attempts:
2 left
💡 Hint
This error usually means the port is busy.
✅ Best Practice
expert
2:00remaining
Best practice for secret management in CI/CD for Flask
What is the best practice to handle sensitive environment variables like API keys in a CI/CD pipeline for a Flask app?
AStore secrets directly in the Flask app source code.
BCommit secrets in a separate config file in the repository.
CUse environment variables set securely in the CI/CD platform and inject them at runtime.
DPrint secrets in the CI/CD logs for debugging.
Attempts:
2 left
💡 Hint
Think about security and avoiding exposure of secrets.

Practice

(1/5)
1. What is the main purpose of a CI/CD pipeline for a Flask application?
easy
A. To automate testing and deployment whenever code changes
B. To manually deploy code after testing
C. To write Flask application code faster
D. To create user interfaces automatically

Solution

  1. Step 1: Understand CI/CD pipeline role

    A CI/CD pipeline automates the process of testing and deploying code changes to catch errors early and speed up delivery.
  2. Step 2: Match purpose with options

    To automate testing and deployment whenever code changes correctly states automation of testing and deployment on code changes, which is the main goal of CI/CD.
  3. Final Answer:

    To automate testing and deployment whenever code changes -> Option A
  4. Quick Check:

    CI/CD automates testing and deployment = C [OK]
Hint: CI/CD means automatic test and deploy on code change [OK]
Common Mistakes:
  • Thinking CI/CD writes code
  • Confusing manual deployment with CI/CD
  • Assuming CI/CD creates UI automatically
2. Which of the following is a correct minimal GitHub Actions workflow file name and location for a Flask CI/CD pipeline?
easy
A. .github/workflows/flask-ci.yml
B. github/actions/flask-ci.yaml
C. .github/actions/flask-ci.yml
D. workflows/.github/flask-ci.yml

Solution

  1. Step 1: Identify GitHub Actions workflow file location

    GitHub Actions requires workflow files inside the repository at .github/workflows/ directory.
  2. Step 2: Check file name and extension

    The file should have a .yml or .yaml extension. .github/workflows/flask-ci.yml uses correct directory and file name.
  3. Final Answer:

    .github/workflows/flask-ci.yml -> Option A
  4. Quick Check:

    Workflow files go in .github/workflows/ = D [OK]
Hint: GitHub Actions workflows live in .github/workflows/ [OK]
Common Mistakes:
  • Placing workflow files outside .github/workflows/
  • Using wrong file extensions
  • Misnaming the directory
3. Given this GitHub Actions snippet for a Flask app:
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.12'
      - name: Install dependencies
        run: pip install -r requirements.txt
      - name: Run tests
        run: pytest

What will happen when this workflow runs?
medium
A. It only installs dependencies without running tests
B. It checks out code, sets Python 3.12, installs dependencies, and runs tests
C. It runs tests without installing dependencies
D. It fails because Python version is missing

Solution

  1. Step 1: Analyze each step in the workflow

    The workflow checks out the code, sets up Python 3.12, installs dependencies from requirements.txt, then runs pytest tests.
  2. Step 2: Confirm all steps are present and correct

    All steps are correctly ordered and complete, so the workflow will perform all these actions successfully.
  3. Final Answer:

    It checks out code, sets Python 3.12, installs dependencies, and runs tests -> Option B
  4. Quick Check:

    Checkout + setup + install + test = B [OK]
Hint: Check steps order: checkout, setup, install, test [OK]
Common Mistakes:
  • Assuming tests run without installing dependencies
  • Thinking Python version is missing
  • Ignoring the checkout step
4. You wrote this GitHub Actions step to install dependencies:
- name: Install dependencies
  run: pip install requirements.txt

Why does this step fail in your Flask CI/CD pipeline?
medium
A. Because pip install cannot run in GitHub Actions
B. Because requirements.txt file is missing
C. Because the command should be 'pip install -r requirements.txt'
D. Because Python version is not specified

Solution

  1. Step 1: Identify the pip install syntax error

    The command 'pip install requirements.txt' tries to install a package named 'requirements.txt' instead of reading the file.
  2. Step 2: Correct the command syntax

    The correct command to install from a requirements file is 'pip install -r requirements.txt'. This flag tells pip to read the file.
  3. Final Answer:

    Because the command should be 'pip install -r requirements.txt' -> Option C
  4. Quick Check:

    Use '-r' flag to install from file = A [OK]
Hint: Use 'pip install -r requirements.txt' to install dependencies [OK]
Common Mistakes:
  • Omitting the '-r' flag
  • Assuming pip install can't run in CI
  • Blaming missing Python version
5. You want to deploy your Flask app automatically after tests pass using GitHub Actions. Which step should you add to your workflow to deploy to Heroku?
hard
A. Add a step that runs 'pip install flask-heroku'
B. Add a step that runs 'heroku login' interactively
C. Add a step that copies files to a local folder
D. Add a step using 'akhileshns/heroku-deploy@v3.12.12' action with Heroku API key and app name

Solution

  1. Step 1: Understand automated deployment in GitHub Actions

    To deploy automatically, use a GitHub Action designed for Heroku deployment that accepts API keys and app name securely.
  2. Step 2: Identify correct deployment action

    The 'akhileshns/heroku-deploy@v3.12.12' action is a popular choice for Heroku deployment in GitHub workflows.
  3. Final Answer:

    Add a step using 'akhileshns/heroku-deploy@v3.12.12' action with Heroku API key and app name -> Option D
  4. Quick Check:

    Use Heroku deploy action with API key = A [OK]
Hint: Use Heroku deploy GitHub Action with API key for auto deploy [OK]
Common Mistakes:
  • Trying interactive login in CI
  • Copying files locally instead of deploying
  • Installing unrelated packages
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard