Compare commits
2 Commits
main
...
fix-valida
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ca1ecce00 | ||
| 0384166e39 |
@@ -5,15 +5,12 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- master
|
- master
|
||||||
|
- fix-validation-issues
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
REGISTRY: git.danhenry.dev
|
|
||||||
IMAGE_NAME: git.danhenry.dev/thelab/shopping-list-api
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: gitea
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -33,7 +30,7 @@ jobs:
|
|||||||
run: uv run pytest
|
run: uv run pytest
|
||||||
|
|
||||||
docker-push:
|
docker-push:
|
||||||
runs-on: gitea
|
runs-on: ubuntu-latest
|
||||||
needs: test
|
needs: test
|
||||||
if: gitea.event_name == 'push'
|
if: gitea.event_name == 'push'
|
||||||
steps:
|
steps:
|
||||||
@@ -46,10 +43,19 @@ jobs:
|
|||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Compute image metadata
|
||||||
|
id: meta
|
||||||
|
env:
|
||||||
|
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
|
||||||
|
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||||
|
run: |
|
||||||
|
IMAGE="${DOCKER_REGISTRY}/$(printf '%s' "$GITEA_REPOSITORY" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
echo "image=$IMAGE" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Log in to Gitea container registry
|
- name: Log in to Gitea container registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ secrets.DOCKER_REGISTRY }}
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
@@ -60,7 +66,7 @@ jobs:
|
|||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: |
|
tags: |
|
||||||
${{ env.IMAGE_NAME }}:${{ gitea.sha }}
|
${{ steps.meta.outputs.image }}:${{ gitea.sha }}
|
||||||
${{ env.IMAGE_NAME }}:latest
|
${{ steps.meta.outputs.image }}:latest
|
||||||
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:latest
|
cache-from: type=registry,ref=${{ steps.meta.outputs.image }}:latest
|
||||||
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:latest,mode=max
|
cache-to: type=registry,ref=${{ steps.meta.outputs.image }}:latest,mode=max
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Deploy GitLab EE
|
|
||||||
hosts: gitlab
|
|
||||||
become: true
|
|
||||||
roles:
|
|
||||||
- gitlab
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Deploy Shopping List API
|
|
||||||
hosts: shopping_list_api
|
|
||||||
become: true
|
|
||||||
roles:
|
|
||||||
- shopping_list_api
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
---
|
|
||||||
gitlab_base_path: "{{ base_config_dir }}/gitlab"
|
|
||||||
gitlab_config_path: "{{ gitlab_base_path }}/config"
|
|
||||||
gitlab_logs_path: "{{ gitlab_base_path }}/logs"
|
|
||||||
gitlab_data_path: "{{ gitlab_base_path }}/data"
|
|
||||||
gitlab_state_path: "{{ gitlab_base_path }}/state"
|
|
||||||
|
|
||||||
gitlab_hostname: gitlab.example.com
|
|
||||||
gitlab_external_url: http://gitlab.example.com
|
|
||||||
gitlab_ssh_port: 2222
|
|
||||||
|
|
||||||
gitlab_proxy_port: 8080
|
|
||||||
gitlab_http_port: 80
|
|
||||||
gitlab_https_port: 443
|
|
||||||
|
|
||||||
gitlab_gitlab_ee_image: gitlab/gitlab-ee:latest
|
|
||||||
gitlab_nginx_image: nginx:alpine
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Restart GitLab
|
|
||||||
community.docker.docker_compose_v2:
|
|
||||||
project_src: "{{ gitlab_base_path }}"
|
|
||||||
state: restarted
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
dependencies:
|
|
||||||
- role: docker
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Create GitLab directories
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ item }}"
|
|
||||||
state: directory
|
|
||||||
owner: "{{ docker_uid }}"
|
|
||||||
group: "{{ docker_gid }}"
|
|
||||||
mode: '0755'
|
|
||||||
loop:
|
|
||||||
- "{{ gitlab_config_path }}"
|
|
||||||
- "{{ gitlab_logs_path }}"
|
|
||||||
- "{{ gitlab_data_path }}"
|
|
||||||
- "{{ gitlab_state_path }}"
|
|
||||||
|
|
||||||
- name: Deploy docker-compose.yml
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: docker-compose.yml.j2
|
|
||||||
dest: "{{ gitlab_base_path }}/docker-compose.yml"
|
|
||||||
owner: "{{ docker_uid }}"
|
|
||||||
group: "{{ docker_gid }}"
|
|
||||||
mode: '0600'
|
|
||||||
notify: Restart GitLab
|
|
||||||
|
|
||||||
- name: Deploy nginx reverse proxy config
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: nginx.conf.j2
|
|
||||||
dest: "{{ gitlab_base_path }}/nginx.conf"
|
|
||||||
owner: "{{ docker_uid }}"
|
|
||||||
group: "{{ docker_gid }}"
|
|
||||||
mode: '0644'
|
|
||||||
notify: Restart GitLab
|
|
||||||
|
|
||||||
- name: Deploy GitLab via Docker Compose
|
|
||||||
community.docker.docker_compose_v2:
|
|
||||||
project_src: "{{ gitlab_base_path }}"
|
|
||||||
state: present
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
---
|
|
||||||
services:
|
|
||||||
gitlab:
|
|
||||||
image: {{ gitlab_gitlab_ee_image }}
|
|
||||||
hostname: {{ gitlab_hostname }}
|
|
||||||
environment:
|
|
||||||
GITLAB_EXTERNAL_URL: "{{ gitlab_external_url }}"
|
|
||||||
GITLAB_SSH_PORT: {{ gitlab_ssh_port }}
|
|
||||||
ports:
|
|
||||||
- "{{ gitlab_ssh_port }}:22"
|
|
||||||
volumes:
|
|
||||||
- {{ gitlab_config_path }}:/etc/gitlab
|
|
||||||
- {{ gitlab_logs_path }}:/var/log/gitlab
|
|
||||||
- {{ gitlab_data_path }}:/var/opt/gitlab
|
|
||||||
- {{ gitlab_state_path }}:/var/gitlab/state
|
|
||||||
restart: unless-stopped
|
|
||||||
shm_size: '256m'
|
|
||||||
|
|
||||||
proxy:
|
|
||||||
image: {{ gitlab_nginx_image }}
|
|
||||||
ports:
|
|
||||||
- "{{ gitlab_proxy_port }}:80"
|
|
||||||
- "{{ gitlab_https_port }}:443"
|
|
||||||
volumes:
|
|
||||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
|
||||||
depends_on:
|
|
||||||
gitlab:
|
|
||||||
condition: service_started
|
|
||||||
restart: unless-stopped
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
upstream gitlab {
|
|
||||||
server gitlab:{{ gitlab_http_port }};
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name {{ gitlab_hostname }};
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://gitlab;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
proxy_buffering off;
|
|
||||||
proxy_request_buffering off;
|
|
||||||
}
|
|
||||||
|
|
||||||
# GitLab WebSocket support for git clone via HTTP
|
|
||||||
location /-/gitlab-lfs/objects {
|
|
||||||
proxy_pass http://gitlab;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
11
main.py
11
main.py
@@ -107,17 +107,6 @@ class ListWithItems(ListResponse):
|
|||||||
def read_root():
|
def read_root():
|
||||||
return {"message": "Shopping List API"}
|
return {"message": "Shopping List API"}
|
||||||
|
|
||||||
@app.get("/health", tags=["meta"])
|
|
||||||
def health_check():
|
|
||||||
conn = get_db()
|
|
||||||
try:
|
|
||||||
conn.execute("SELECT 1").fetchone()
|
|
||||||
conn.close()
|
|
||||||
return {"status": "ok"}
|
|
||||||
except Exception as e:
|
|
||||||
conn.close()
|
|
||||||
return {"status": "error", "detail": str(e)}, 503
|
|
||||||
|
|
||||||
@app.post("/products", response_model=ProductResponse, status_code=201, tags=["products"])
|
@app.post("/products", response_model=ProductResponse, status_code=201, tags=["products"])
|
||||||
def create_product(product: Product):
|
def create_product(product: Product):
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
|
|||||||
Reference in New Issue
Block a user