Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(api): move api to this repository #157

Merged
merged 13 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ ENV=development
#* Database

DB_NAME=urbantree
DB_USER=root
# If user is root, both PASS and ROOT_PASS should be the same
DB_USER=urbantree
DB_PASS=J0HMXAJ6XE
DB_ROOT_PASS="J0¿H.MXA;'J6!XE"
# If you are using docker-compose, you can ignore the following variables
DB_HOST=database
DB_PORT=3306
9 changes: 8 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ updates:
labels:
- "kind/dependencies"
- "needs-triage"
- package-ecosystem: "pip"
directory: "/api"
schedule:
interval: "weekly"
labels:
- "kind/dependencies"
- "needs-triage"
- package-ecosystem: "docker"
directory: "/"
schedule:
Expand All @@ -25,4 +32,4 @@ updates:
interval: "weekly"
labels:
- "kind/dependencies"
- "needs-triage"
- "needs-triage"
4 changes: 4 additions & 0 deletions .github/file-filters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
api: &api
- "api/**"
urbantree:
- "!(*api)"
45 changes: 35 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,44 @@ env:
REGISTRY: ghcr.io

jobs:
changes:
name: 🔄 Detect changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
images: ${{ steps.filter.outputs.changes }}
steps:
# https://github.com/actions/checkout/tree/11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
# https://github.com/dorny/paths-filter/tree/de90cc6fb38fc0963ad72b210f1f284cd68cea36
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
id: filter
with:
filters: .github/file-filters.yml

tests:
name: 🧪 Tests
needs: changes
uses: ./.github/workflows/tests.yml
with:
images: ${{ needs.changes.outputs.images }}
secrets: inherit

build:
name: 🐳 Docker
runs-on: ubuntu-latest
needs: tests
needs: [changes, tests]
strategy:
fail-fast: false
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow#example-adding-configurations
matrix:
image: [urbantree]
image: ${{ fromJSON(needs.changes.outputs.images) }}
include:
- image: urbantree
context: .
- image: api
context: ./api
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -80,6 +101,7 @@ jobs:
with:
path: |
composer-cache
python-cache
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}

# https://github.com/reproducible-containers/buildkit-cache-dance/tree/5b6db76d1da5c8b307d5d2e0706d266521b710de
Expand All @@ -88,7 +110,8 @@ jobs:
with:
cache-map: |
{
"composer-cache": "/tmp/cache"
"composer-cache": "/tmp/cache",
"python-cache": "/root/.cache/pip"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}

Expand All @@ -110,7 +133,7 @@ jobs:
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
# https://github.com/sigstore/cosign/
- name: 🖋️ Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
Expand Down Expand Up @@ -141,12 +164,14 @@ jobs:
- name: 🚚 SSH into production server
uses: appleboy/ssh-action@7eaf76671a0d7eec5d98ee897acda4f968735a17
with:
host: ${{ secrets.PRODUCTION_SERVER }}
username: ${{ secrets.PRODUCTION_SERVER_USERNAME }}
password: ${{ secrets.PRODUCTION_SERVER_KEY }}
port: ${{ secrets.PRODUCTION_SERVER_PORT }}
host: ${{ secrets.SSH_MANAGER_HOST }}
username: ${{ secrets.SSH_MANAGER_USER }}
password: ${{ secrets.SSH_MANAGER_PASS }}
port: ${{ secrets.SSH_MANAGER_PORT }}
script: |
docker compose -f docker-compose.prod.yml up -d --no-deps
docker stack deploy --with-registry-auth -c compose.prod.yml urbantree

- name: 🕵️ Check the deployment
run: curl -sSf http://${{ secrets.PRODUCTION_SERVER }}/
run: |
# curl -sSf http://${{ env.WEB_URL }}/
curl -sSf http://${{ env.API_URL }}/
50 changes: 50 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ name: 🧪 Tests

on:
workflow_call:
inputs:
images:
required: true
type: string

jobs:
urbantree:
name: 🧪 UrbanTree
runs-on: ubuntu-latest
if: ${{ contains(fromJSON(inputs.images), 'urbantree') }}
steps:
# https://github.com/actions/checkout/tree/11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
Expand Down Expand Up @@ -49,3 +54,48 @@ jobs:
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

api:
name: 🧪 API
runs-on: ubuntu-latest
if: ${{ contains(fromJSON(inputs.images), 'api') }}
steps:
# https://github.com/actions/checkout/tree/11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
# https://github.com/actions/cache/tree/6849a6489940f00c2f30c0fb92c6274307ccb58a
- name: 📦 Cache Python dependencies
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
with:
path: /root/.cache/pip
key: ${{ runner.os }}-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}

# https://github.com/actions/setup-python/tree/0b93645e9fea7318ecaed2b359559ac225c90a2b
- name: 🐍 Setup Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: "3.13.0"

- name: 📦 Install Python dependencies
shell: bash
working-directory: api
run: pip install -r requirements-dev.txt

- name: 🧪 Run Python tests with coverage
shell: bash
working-directory: api
run: pytest tests --cov=./src --cov-report=xml --junitxml=junit.xml

# https://github.com/codecov/test-results-action/tree/9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820
- name: 📊 Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

# https://github.com/codecov/codecov-action/tree/015f24e6818733317a2da2edd6290ab26238649a
- name: Upload coverage to Codecov
uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a
with:
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#! Custom

junit.xml
/coverage/

# Created by https://www.toptal.com/developers/gitignore/api/git,dotenv,phpunit,composer,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=git,dotenv,phpunit,composer,visualstudiocode

Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"yaml.schemas": {
"https://json.schemastore.org/pull-request-labeler-5.json": ".github/labeler.yml"
"https://json.schemastore.org/pull-request-labeler-5.json": ".github/labeler.yml",
"https://raw.githubusercontent.com/compose-spec/compose-spec/refs/heads/main/schema/compose-spec.json": "compose.test.yml"
}
}
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ COPY ./src /var/www/html
FROM base AS development
# Add PECL extensions, and enable Xdebug.
# See https://github.com/docker-library/docs/tree/master/php#pecl-extensions
# RUN pecl install xdebug-3.2.1 \
# RUN pecl install xdebug \
# && docker-php-ext-enable xdebug
# COPY ./.docker/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
COPY --from=dev-deps app/vendor/ /var/www/html/vendor
COPY ./tests /var/www/html/tests
Expand All @@ -40,7 +41,9 @@ COPY ./phpunit.xml** /var/www/html
#* Run tests when building
FROM development AS test
WORKDIR /var/www/html
RUN ./vendor/bin/phpunit
# ENV XDEBUG_MODE coverage
# CMD ["./vendor/bin/phpunit", "--log-junit", "junit.xml", "--coverage-clover=coverage.xml"]
CMD ["./vendor/bin/phpunit"]

#* Create a production stage.
FROM base AS final
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ Aplicatiu web per a la gestió del manteniment d'arbrat urbà i periurbà.

## Instruccions d'instal·lació

**Arrencar l'entorn amb Docker:**
**1. Configurar les variables d'entorn**

En base al fitxer `.env.example`, crea un fitxer similar a la mateixa carpeta amb el nom `.env`, modificant les variables d'entorn per tal que s'adaptin a les teves necessitats.

**2. Arrencar l'entorn amb Docker**

Executa el següent comandament:

```bash
docker-compose up --build --watch --remove-orphans
```

Executar-ho crearà els contenidors necessaris per al projecte i posarà en marxa l'aplicació.
Executar-ho crearà els contenidors necessaris per al projecte i posarà en marxa el projecte!

---
Aquestes són les URL's d'accés a les diferents parts de l'aplicació en entorn de desenvolupament:

Accedir a l'aplicació en entorn de desenvolupament: [http://localhost:8000](http://localhost:8000)

Accedir al phpMyAdmin:: [http://localhost:8080](http://localhost:8080)
- L'aplicatiu: [http://localhost:8000](http://localhost:8000)
- L'API: [http://localhost:8001](http://localhost:8001)
- El phpMyAdmin: [http://localhost:8080](http://localhost:8080)
34 changes: 34 additions & 0 deletions api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/

**/.DS_Store
**/__pycache__
**/.venv
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose.y*ml
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
Loading
Loading