Skip to content

Commit 713eac9

Browse files
authored
Add initial config for user auth (#10)
1 parent b77125d commit 713eac9

File tree

7 files changed

+142
-2
lines changed

7 files changed

+142
-2
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
name: Create and publish a Docker image
3+
4+
on:
5+
release:
6+
types: [published]
7+
8+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
14+
jobs:
15+
build-and-push-image:
16+
strategy:
17+
matrix:
18+
target:
19+
- web-conexs-api
20+
- web-conexs-client
21+
runs-on: ubuntu-latest
22+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
23+
permissions:
24+
contents: read
25+
packages: write
26+
attestations: write
27+
id-token: write
28+
#
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
33+
- name: Log in to the Container registry
34+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Generate Image Name
41+
run: echo IMAGE_REPOSITORY=ghcr.io/$(echo "${{ github.repository }}-${{ matrix.target }}" | tr '[:upper:]' '[:lower:]' | tr '[_]' '[\-]') >> $GITHUB_ENV
42+
43+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
44+
- name: Extract metadata (tags, labels) for Docker
45+
id: meta
46+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
47+
with:
48+
images: ${{ env.IMAGE_REPOSITORY }}
49+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
50+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
51+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
52+
- name: Build and push Docker image
53+
id: push
54+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
55+
with:
56+
context: ./${{ matrix.target }}/
57+
push: true
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}
60+
61+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
62+
- name: Generate artifact attestation
63+
uses: actions/attest-build-provenance@v1
64+
with:
65+
subject-name: ${{ env.IMAGE_REPOSITORY }}
66+
subject-digest: ${{ steps.push.outputs.digest }}
67+
push-to-registry: true
68+

web-conexs-api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ COPY --from=build /venv/ /venv/
2525
ENV PATH=/venv/bin:$PATH
2626

2727
# change this entrypoint if it is not the same as the repo
28-
ENTRYPOINT ["web-conexs-api"]
28+
ENTRYPOINT ["python"]
2929
CMD ["--version"]
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastapi import FastAPI
22
from fastapi_pagination import add_pagination
33

4-
from .routers import crystals, fdmnes, molecules, orca, simulations
4+
from .routers import crystals, fdmnes, molecules, orca, simulations, user
55

66
app = FastAPI()
77

@@ -10,5 +10,6 @@
1010
app.include_router(molecules.router)
1111
app.include_router(crystals.router)
1212
app.include_router(simulations.router)
13+
app.include_router(user.router)
1314

1415
add_pagination(app)

web-conexs-api/src/web_conexs_api/crud.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,10 @@ def get_orca_xas(session, id, user_id):
328328
}
329329

330330
return output
331+
332+
333+
def get_user(session, user_id):
334+
statement = select(Person).where(Person.identifier == user_id)
335+
person = session.exec(statement).first()
336+
337+
return person
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from fastapi import APIRouter, Depends
2+
from sqlmodel import Session
3+
4+
from ..auth import get_current_user
5+
from ..crud import get_user
6+
from ..database import get_session
7+
8+
router = APIRouter()
9+
10+
11+
@router.get("/api/user")
12+
async def check(
13+
session: Session = Depends(get_session), user_id: str = Depends(get_current_user)
14+
):
15+
return get_user(session, user_id)

web-conexs-client/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#build client
2+
#build api
3+
#copy to runtime
4+
5+
FROM node:18-bullseye-slim as build-web
6+
7+
WORKDIR /client
8+
9+
RUN yes | npm install -g pnpm
10+
11+
RUN apt update
12+
13+
COPY . .
14+
15+
RUN yes | pnpm install
16+
17+
RUN pnpm vite build
18+
19+
From nginx as host
20+
21+
COPY --from=build-web /client/dist/ /usr/share/nginx/html
22+
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
23+
24+
# change this entrypoint if it is not the same as the repo
25+
ENTRYPOINT ["nginx","-g", "daemon off;"]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
5+
#access_log /var/log/nginx/host.access.log main;
6+
7+
8+
location / {
9+
root /usr/share/nginx/html;
10+
index index.html index.htm;
11+
try_files $uri /index.html =404;
12+
}
13+
14+
#error_page 404 /404.html;
15+
16+
# redirect server error pages to the static page /50x.html
17+
#
18+
error_page 500 502 503 504 /50x.html;
19+
location = /50x.html {
20+
root /usr/share/nginx/html;
21+
}
22+
23+
24+
}

0 commit comments

Comments
 (0)