commit b76ad1afe8e92b0c9f27cc5190240fede43ca64b Author: github-classroom[bot] <66690702+github-classroom[bot]@users.noreply.github.com> Date: Thu Jan 16 17:29:37 2025 +0000 Initial commit diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..f9ae4da --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,79 @@ +name: Run tests + +on: deployment + +permissions: + contents: read + packages: write + attestations: write + id-token: write + + +jobs: + build: + name: Build image + runs-on: ubuntu-latest + timeout-minutes: 10 + if: github.action != 'github-classroom[bot]' + steps: + - uses: actions/checkout@v4 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Save image name (lowercased) + run: echo "IMAGE_NAME=$(echo 'ghcr.io/${{ github.repository }}:run-${{ github.run_id }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + - name: Build and push image + uses: docker/build-push-action@v4 + with: + context: ./solution + file: ./solution/Dockerfile + tags: ${{ env.IMAGE_NAME }} + push: true + + tests: + needs: build + name: Run tests + runs-on: ubuntu-latest + timeout-minutes: 20 + if: github.action != 'github-classroom[bot]' + steps: + - name: Setup checker environment + uses: Central-University-IT/setup-test-2025-backend@v1 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Run tests + run: | + export IMAGE_SOLUTION=$(echo 'ghcr.io/${{ github.repository }}:run-${{ github.run_id }}' | tr '[:upper:]' '[:lower:]') + export IMAGE_ANTIFRAUD=docker.io/lodthe/prod-backend-antifraud + /usr/local/bin/checker + continue-on-error: true + + - uses: actions/upload-artifact@v4.0.0 + with: + name: result + path: ./result.json + if-no-files-found: error + compression-level: 0 + + - uses: bots-house/ghcr-delete-image-action@v1.1.0 + continue-on-error: true + with: + owner: ${{ github.repository_owner }} + name: ${{ github.event.repository.name }} + token: ${{ secrets.GITHUB_TOKEN }} + tag: run-${{ github.run_id }} diff --git a/README.md b/README.md new file mode 100644 index 0000000..7f64bac --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# PROMO v2: Promo Code Backend + +Это ваш личный репозиторий для решения второго этапа в треке Backend. +Вы можете редактировать файлы **только в директории `solution`**. + +Условие задания и публичные тесты доступны [в данном репозитории](https://github.com/Central-University-IT/FAQ-2025/tree/main/backend). \ No newline at end of file diff --git a/solution/.dockerignore b/solution/.dockerignore new file mode 100644 index 0000000..d3ae326 --- /dev/null +++ b/solution/.dockerignore @@ -0,0 +1,5 @@ +.dockerignore +Dockerfile +README.md +.venv/ +__pycache__/ diff --git a/solution/.gitignore b/solution/.gitignore new file mode 100644 index 0000000..808386f --- /dev/null +++ b/solution/.gitignore @@ -0,0 +1,2 @@ +.venv/ +__pycache__/ \ No newline at end of file diff --git a/solution/Dockerfile b/solution/Dockerfile new file mode 100644 index 0000000..a19cae9 --- /dev/null +++ b/solution/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.12-alpine3.21 + +WORKDIR /usr/src/app + +COPY requirements.txt . +RUN pip install -r requirements.txt + +COPY . . + +CMD [ "python", "./main.py" ] diff --git a/solution/main.py b/solution/main.py new file mode 100644 index 0000000..0631399 --- /dev/null +++ b/solution/main.py @@ -0,0 +1,14 @@ +import os +from fastapi import FastAPI +import uvicorn + +app = FastAPI() + +@app.get("/api/ping") +def send(): + return {"status": "ok"} + +if __name__ == "__main__": + server_address = os.getenv("SERVER_ADDRESS", "0.0.0.0:8080") + host, port = server_address.split(":") + uvicorn.run(app, host=host, port=int(port)) diff --git a/solution/requirements.txt b/solution/requirements.txt new file mode 100644 index 0000000..97dc7cd --- /dev/null +++ b/solution/requirements.txt @@ -0,0 +1,2 @@ +fastapi +uvicorn