diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..471ac83 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +.env +.git +.gitignore +Dockerfile +docker-compose.yml +*.md +assets +tests +.pytest_cache diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml new file mode 100644 index 0000000..1b47204 --- /dev/null +++ b/.github/workflows/prod.yml @@ -0,0 +1,66 @@ +name: CI/CD PROD + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + +jobs: + build: + timeout-minutes: 3 + name: build + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: write + actions: read + checks: write + steps: + - name: Checkout code + uses: actions/checkout@main + + - name: Config QEMU + uses: docker/setup-qemu-action@v3.2.0 + with: + platforms: linux/amd64 + + - name: Config Docker Buildx + uses: docker/setup-buildx-action@v3.7.1 + with: + platforms: linux/amd64 + + - name: Login to Docker Hub + uses: docker/login-action@v3.3.0 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: Build and Publish Image to Docker Hub + run: | + docker build -t r4deu51/api-b3:${{ github.ref_name }} . + docker tag r4deu51/api-b3:${{ github.ref_name }} docker.io/r4deu51/api-b3:${{ github.ref_name }} + docker push docker.io/r4deu51/api-b3:${{ github.ref_name }} + + # ============================================ + # DEPLOY + # ============================================ + deploy: + timeout-minutes: 1 + needs: build + name: deploy + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: read + actions: read + checks: write + steps: + - name: Checkout code + uses: actions/checkout@main + + - name: Deploy Image + uses: ramonpaolo/action-zenifra@main + with: + PROJECT_ID: ${{ secrets.ZENIFRA_PROJECT_ID_PROD }} + API_KEY: ${{ secrets.ZENIFRA_API_KEY_PROD }} + IMAGE: docker.io/r4deu51/api-b3:${{ github.ref_name }} diff --git a/.github/workflows/stg.yml b/.github/workflows/stg.yml new file mode 100644 index 0000000..cfe20da --- /dev/null +++ b/.github/workflows/stg.yml @@ -0,0 +1,67 @@ +name: CI/CD STG + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + timeout-minutes: 3 + name: build + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: write + actions: read + checks: write + steps: + - name: Checkout code + uses: actions/checkout@main + + - name: Config QEMU + uses: docker/setup-qemu-action@v3.2.0 + with: + platforms: linux/amd64 + + - name: Config Docker Buildx + uses: docker/setup-buildx-action@v3.7.1 + with: + platforms: linux/amd64 + + - name: Login to Docker Hub + uses: docker/login-action@v3.3.0 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: Build and Publish Image to Docker Hub + run: | + docker build -t r4deu51/api-b3:${{ github.sha }} . + docker tag r4deu51/api-b3:${{ github.sha }} docker.io/r4deu51/api-b3:${{ github.sha }} + docker push docker.io/r4deu51/api-b3:${{ github.sha }} + + # ============================================ + # DEPLOY + # ============================================ + deploy: + timeout-minutes: 1 + needs: build + name: deploy + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: read + actions: read + checks: write + steps: + - name: Checkout code + uses: actions/checkout@main + + - name: Deploy Image + uses: ramonpaolo/action-zenifra@main + with: + PROJECT_ID: ${{ secrets.ZENIFRA_PROJECT_ID_STG }} + API_KEY: ${{ secrets.ZENIFRA_API_KEY_STG }} + IMAGE: docker.io/r4deu51/api-b3:${{ github.sha }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..434c92d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.13-slim + +WORKDIR /app + +RUN apt-get update && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt . + +RUN pip install --no-cache-dir -r requirements.txt + +COPY ./ ./ + +EXPOSE 8000 + +RUN addgroup -S appgroup && adduser -S appuser -G appgroup + +USER appuser + +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/Procfile b/Procfile deleted file mode 100644 index 81a08ac..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: uvicorn main:app --host=0.0.0.0 --port=${PORT:-5000} \ No newline at end of file