generated from hjess/PythonTemplateProject
First real commit
Some checks failed
Build, Push, and Deploy to Nomad / docker-nomad (push) Failing after 1m5s
Some checks failed
Build, Push, and Deploy to Nomad / docker-nomad (push) Failing after 1m5s
This commit is contained in:
63
.gitea/workflows/main.yml
Normal file
63
.gitea/workflows/main.yml
Normal file
@@ -0,0 +1,63 @@
|
||||
name: Build, Push, and Deploy to Nomad
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
docker-nomad:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Log in to Container Registry
|
||||
run: echo ${{ secrets.password }} | docker login registry.i80.dk -u ${{ secrets.username }} --password-stdin
|
||||
|
||||
- name: Build Docker Image
|
||||
run: |
|
||||
COMMIT_HASH=$(git rev-parse --short HEAD)
|
||||
docker build -t registry.i80.dk/gitea/lifefaq:latest -t registry.i80.dk/gitea/lifefaq:${COMMIT_HASH} .
|
||||
|
||||
|
||||
- name: Push Docker Image
|
||||
run: |
|
||||
COMMIT_HASH=$(git rev-parse --short HEAD)
|
||||
echo "registry.i80.dk/gitea/lifefaq:latest"
|
||||
echo "registry.i80.dk/gitea/lifefaq:${COMMIT_HASH}"
|
||||
docker push registry.i80.dk/gitea/lifefaq:${COMMIT_HASH}
|
||||
docker push registry.i80.dk/gitea/lifefaq:latest
|
||||
|
||||
|
||||
- name: Validate Nomad Job
|
||||
env:
|
||||
NOMAD_ADDR: https://nomad.i80.dk
|
||||
run: nomad job validate .gitea/workflows/nomad-job.hcl
|
||||
|
||||
- name: Stop old deployment
|
||||
env:
|
||||
NOMAD_ADDR: https://nomad.i80.dk
|
||||
run: nomad job stop -purge -no-shutdown-delay lifefaq
|
||||
continue-on-error: true
|
||||
|
||||
|
||||
- name: Apply Nomad Job
|
||||
env:
|
||||
NOMAD_ADDR: https://nomad.i80.dk
|
||||
run: nomad job run .gitea/workflows/nomad-job.hcl
|
||||
|
||||
- name: Update Nginx Configuration
|
||||
run: ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/nginx_updater.py lifefaq
|
||||
|
||||
- name: Update Forwarder Configuration
|
||||
run: ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/update_forwarder.py lifefaq
|
||||
|
||||
|
||||
# - name: Restart Nomad Job
|
||||
# env:
|
||||
# NOMAD_ADDR: https://nomad.i80.dk
|
||||
# run: |
|
||||
# nomad job stop lifefaq
|
||||
# sleep 5 # Optional: Wait to ensure the old allocation is stopped
|
||||
# nomad job run .gitea/workflows/nomad-job.hcl
|
||||
60
.gitea/workflows/nomad-job.hcl
Normal file
60
.gitea/workflows/nomad-job.hcl
Normal file
@@ -0,0 +1,60 @@
|
||||
job "lifefaq" {
|
||||
region = "global"
|
||||
datacenters = ["dc1"]
|
||||
type = "service"
|
||||
|
||||
update {
|
||||
stagger = "60s"
|
||||
max_parallel = 1
|
||||
progress_deadline = "6m"
|
||||
}
|
||||
|
||||
group "lifefaq-group" {
|
||||
count = 1
|
||||
|
||||
network {
|
||||
port "port-app" {
|
||||
to = 9210 # Internal application port
|
||||
}
|
||||
}
|
||||
|
||||
# Register the service with Consul
|
||||
service {
|
||||
provider = "consul"
|
||||
name = "lifefaq"
|
||||
port = "port-app"
|
||||
|
||||
# Traefik-specific tags for routing
|
||||
tags = [
|
||||
"PORT=${NOMAD_PORT_port-app}"
|
||||
]
|
||||
|
||||
# Define a health check using TCP
|
||||
check {
|
||||
name = "tcp_check"
|
||||
type = "tcp"
|
||||
interval = "10s"
|
||||
timeout = "2s"
|
||||
}
|
||||
}
|
||||
|
||||
task "lifefaq-task" {
|
||||
driver = "docker"
|
||||
|
||||
config {
|
||||
image = "registry.i80.dk/gitea/lifefaq:latest"
|
||||
ports = ["port-app"]
|
||||
}
|
||||
|
||||
env {
|
||||
APP_ENV = "production"
|
||||
PORT = "${NOMAD_PORT_port-app}"
|
||||
}
|
||||
|
||||
resources {
|
||||
cpu = 250
|
||||
memory = 80
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
.python-version
Normal file
1
.python-version
Normal file
@@ -0,0 +1 @@
|
||||
3.11.7
|
||||
11
Dockerfile
11
Dockerfile
@@ -13,13 +13,8 @@ RUN pip install --no-cache-dir -r requirements.txt
|
||||
# Copy the rest of the application code
|
||||
COPY . .
|
||||
|
||||
# Expose the port the app runs on (default Flask port)
|
||||
# Expose the port the FastAPI app runs on (default Uvicorn port)
|
||||
EXPOSE 5000
|
||||
|
||||
# Define environment variables
|
||||
ENV FLASK_APP=app.py
|
||||
ENV FLASK_RUN_HOST=0.0.0.0
|
||||
ENV PORT=5000
|
||||
# Command to run the application
|
||||
#CMD ["flask", "run", "--port", "${PORT}"]
|
||||
CMD flask run --port ${PORT}
|
||||
# Command to run the FastAPI application
|
||||
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "5000", "--workers", "1"]
|
||||
11
app.py
Normal file
11
app.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from fastapi import FastAPI
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
|
||||
app = FastAPI(title=os.getenv("APP_NAME", "Default App"))
|
||||
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return {"debug": os.getenv("DEBUG", "false")}
|
||||
@@ -0,0 +1,4 @@
|
||||
fastapi==0.110.0 # Latest FastAPI version
|
||||
uvicorn[standard]==0.27.1 # ASGI server to run FastAPI
|
||||
pydantic==2.6.3
|
||||
python-dotenv==1.0.1 # Manage environment variables
|
||||
Reference in New Issue
Block a user