Skip to content

Commit

Permalink
Merge branch 'main' into UI-Start
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Johnson authored and Dylan Johnson committed Jan 24, 2025
2 parents ef6a83b + b7e8d0f commit 0c37824
Show file tree
Hide file tree
Showing 23 changed files with 3,950 additions and 4,558 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web/node_modules
50 changes: 50 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build

on:
push:
branches:
- main

env:
IMAGE: ${{ secrets.IMAGE_URL }}
PAT: ${{ secrets.PAT }}

jobs:
build-api:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./api
steps:
- uses: actions/checkout@v4

- name: Registry login
run: echo $PAT | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin

- name: Pull Docker Image
run: docker pull $IMAGE/api:latest

- name: Tag Docker Image
run: docker build . --tag $IMAGE/api:latest --cache-from $IMAGE:latest

- name: Push Docker Image
run: docker push $IMAGE/api:latest
build-web:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./web
steps:
- uses: actions/checkout@v4

- name: Registry login
run: echo $PAT | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin

- name: Pull Docker Image
run: docker pull $IMAGE/web:latest

- name: Tag Docker Image
run: docker build . --tag $IMAGE/web:latest --cache-from $IMAGE:latest

- name: Push Docker Image
run: docker push $IMAGE/web:latest
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
# MacOS
.DS_Store

# Logs
*.log

# Python
*.pyc
__pycache__

# Secrets
*.key
*.cer

# Virtual Environment
.venv/

Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: run
.PHONY: build up stop down
include api/.env
export

Expand Down Expand Up @@ -26,14 +26,14 @@ down:
attach-web:
docker attach resdeeds-web

# target: attack-api - Attach to the running container.
# target: attach-api - Attach to the running container.
attach-api:
docker attach resdeeds-api

# target: bash-api - Run bash in the container.
bash-api:
docker exec -it resdeeds-api bash

# target: shell - Run shell in the container.
shell:
docker exec -it resdeeds-api flask shell
# target: run-api - Run the api locally
run-api:
cd api && uvicorn src.main:app --host 0.0.0.0 --port 5000 --reload
9 changes: 9 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ WORKDIR /var/www

COPY . /var/www

# Configure INL certs and environment variables
ADD http://certstore.inl.gov/pki/CAINLROOT_B64.crt /usr/local/share/ca-certificates/
RUN /usr/sbin/update-ca-certificates
ENV NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt \
REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt \
CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt \
SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt \
SSL_CERT_DIR=/etc/ssl/certs/

# Install dependencies
RUN apt-get update \
&& apt-get install -y build-essential cargo
Expand Down
4 changes: 1 addition & 3 deletions api/etc/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ echo "Launching ResDEEDS API..."
if [[ $DEBUG -eq 1 ]];
then
echo "Running in debug mode"
python -m debugpy \
--listen 0.0.0.0:5678 \
-m uvicorn src.main:app \
uvicorn src.main:app \
--host 0.0.0.0 \
--port 5000 \
--reload
Expand Down
1 change: 0 additions & 1 deletion api/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--requirement requirements.txt
black
debugpy
ipdb
8 changes: 7 additions & 1 deletion api/src/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from src.routes import auth, projects

app = FastAPI(title="ResDEEDS")

app.add_middleware(
CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]
)


app.include_router(auth.router, tags=["Auth"], prefix="/api/auth")
app.include_router(projects.router, tags=["Projects"], prefix="/api/projects")


@app.get("/")
def read_root():
def health_check():
"""Hello World root."""
return {"Hello": "World"}
18 changes: 18 additions & 0 deletions deploy/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

echo "Stopping existing container.."
dzdo docker stop resdeeds-web

echo "Pulling latest image.."
dzdo docker pull ghcr.io/idaholab/resdeeds/web:latest

echo "Launching latest container"
dzdo docker run -d --rm \
-p 80:80 -p 443:443 \
--name resdeeds-web \
-v ./etc/ssl:/etc/ssl \
-v ./etc/nginx:/etc/nginx/conf.d \
-v /var/log/nginx:/var/log/nginx \
ghcr.io/idaholab/resdeeds/web:latest

echo "Deployed"
Empty file added deploy/main.py
Empty file.
10 changes: 7 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,32 @@ services:
build:
context: ./web
dockerfile: Dockerfile
image: ghcr.io/idaholab/resdeeds/web
container_name: resdeeds-web
# depends_on:
# - api
ports:
- 80:80
- 443:443
- 4200:4200
stdin_open: true
tty: true
volumes:
- ./web:/var/www
- node_modules:/var/www/node_modules
- ./web/etc/ssl:/etc/ssl
- ./web/etc/nginx/conf.d:/etc/nginx/conf.d
- ./web/etc/nginx/log:/var/log/nginx
api:
build:
context: ./api
dockerfile: Dockerfile
image: ghcr.io/idaholab/resdeeds/api
container_name: resdeeds-api
depends_on:
- mongodb
env_file:
- ./api/.env
ports:
- 5000:5000
- 5678:5678
stdin_open: true
tty: true
volumes:
Expand Down
27 changes: 21 additions & 6 deletions web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
FROM node:20-alpine
FROM node:22 AS build

WORKDIR /var/www

COPY . /var/www/
RUN npm config set strict-ssl false
RUN npm install -g @angular/cli

RUN npm install
# Configure INL certs and environment variables
ADD http://certstore.inl.gov/pki/CAINLROOT_B64.crt /usr/local/share/ca-certificates/
RUN /usr/sbin/update-ca-certificates
ENV NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt \
REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt \
CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt \
SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt \
SSL_CERT_DIR=/etc/ssl/certs/

EXPOSE 4200
RUN apt-get update
RUN npm i -g @angular/cli \
&& npm i

CMD ["ng", "serve", "--host", "0.0.0.0"]
RUN ng build --configuration=production

FROM nginx:alpine

COPY --from=build /var/www/dist/resdeeds /usr/share/nginx/html

EXPOSE 80 443 4200

CMD ["nginx", "-g", "daemon off;"]
17 changes: 12 additions & 5 deletions web/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
}
],
"styles": [
"./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css", "src/styles.scss"
"./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css", "src/styles.scss",
"src/styles.scss",
"node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"node_modules/bootstrap/dist/js/bootstrap.min.js"
],
"scripts": [],
"server": "src/main.server.ts",
"prerender": false,
"ssr": false
Expand Down Expand Up @@ -94,9 +98,12 @@
}
],
"styles": [
"src/styles.scss"
"src/styles.scss",
"node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": []
"scripts": [
"node_modules/bootstrap/dist/js/bootstrap.min.js"
]
}
}
}
Expand All @@ -105,4 +112,4 @@
"cli": {
"analytics": false
}
}
}
49 changes: 49 additions & 0 deletions web/etc/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
server {
listen 443 ssl;
server_name localhost;

# Path to SSL certificate and key
ssl_certificate /etc/ssl/certs/localhost.cer;
ssl_certificate_key /etc/ssl/private/localhost.key;

# Root directory for the Angular app
root /usr/share/nginx/html;

# Default file to serve
index index.html;

# Serve static files from /usr/share/nginx/html
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

# Error pages
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# Optional: Gzip compression for improved performance
gzip on;
gzip_types text/plain application/javascript text/css application/json application/xml text/javascript;
gzip_min_length 1024;
}


server {
listen 80;
server_name localhost;

# Serve static files from /usr/share/nginx/html
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

# Error pages
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Loading

0 comments on commit 0c37824

Please sign in to comment.