Skip to content
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
68 changes: 68 additions & 0 deletions .github/workflows/publish-containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#
name: Create and publish a Docker image

on:
release:
types: [published]

# 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.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
strategy:
matrix:
target:
- web-conexs-api
- web-conexs-client
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
# 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.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate Image Name
run: echo IMAGE_REPOSITORY=ghcr.io/$(echo "${{ github.repository }}-${{ matrix.target }}" | tr '[:upper:]' '[:lower:]' | tr '[_]' '[\-]') >> $GITHUB_ENV

# 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.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.IMAGE_REPOSITORY }}
# 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.
# 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.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: ./${{ matrix.target }}/
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# 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)."
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.IMAGE_REPOSITORY }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

2 changes: 1 addition & 1 deletion web-conexs-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ COPY --from=build /venv/ /venv/
ENV PATH=/venv/bin:$PATH

# change this entrypoint if it is not the same as the repo
ENTRYPOINT ["web-conexs-api"]
ENTRYPOINT ["python"]
CMD ["--version"]
3 changes: 2 additions & 1 deletion web-conexs-api/src/web_conexs_api/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi import FastAPI
from fastapi_pagination import add_pagination

from .routers import crystals, fdmnes, molecules, orca, simulations
from .routers import crystals, fdmnes, molecules, orca, simulations, user

app = FastAPI()

Expand All @@ -10,5 +10,6 @@
app.include_router(molecules.router)
app.include_router(crystals.router)
app.include_router(simulations.router)
app.include_router(user.router)

add_pagination(app)
7 changes: 7 additions & 0 deletions web-conexs-api/src/web_conexs_api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,10 @@ def get_orca_xas(session, id, user_id):
}

return output


def get_user(session, user_id):
statement = select(Person).where(Person.identifier == user_id)
person = session.exec(statement).first()

return person
15 changes: 15 additions & 0 deletions web-conexs-api/src/web_conexs_api/routers/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from fastapi import APIRouter, Depends
from sqlmodel import Session

from ..auth import get_current_user
from ..crud import get_user
from ..database import get_session

router = APIRouter()


@router.get("/api/user")
async def check(
session: Session = Depends(get_session), user_id: str = Depends(get_current_user)
):
return get_user(session, user_id)
25 changes: 25 additions & 0 deletions web-conexs-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#build client
#build api
#copy to runtime

FROM node:18-bullseye-slim as build-web

WORKDIR /client

RUN yes | npm install -g pnpm

RUN apt update

COPY . .

RUN yes | pnpm install

RUN pnpm vite build

From nginx as host

COPY --from=build-web /client/dist/ /usr/share/nginx/html
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf

# change this entrypoint if it is not the same as the repo
ENTRYPOINT ["nginx","-g", "daemon off;"]
24 changes: 24 additions & 0 deletions web-conexs-client/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
server {
listen 80;
server_name localhost;

#access_log /var/log/nginx/host.access.log main;


location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html =404;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}


}