Skip to content

Commit

Permalink
Merge pull request #50 from henilp105/main
Browse files Browse the repository at this point in the history
Add and Refactor and maintainance PR
  • Loading branch information
henilp105 authored Nov 29, 2023
2 parents 2a55a8c + 043b3c7 commit 2d83cdb
Show file tree
Hide file tree
Showing 143 changed files with 670 additions and 956 deletions.
27 changes: 0 additions & 27 deletions .docker/docker-compose.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

jobs:
build:
Expand All @@ -15,7 +16,7 @@ jobs:
uses: actions/checkout@v3

- name: Build the Docker image and run tests
run: docker compose -f "compose.test.yaml" up -d
run: docker compose -f "backend/compose.test.yaml" up -d

- name: Print Logs for Container
run: |
Expand Down
44 changes: 36 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

/.vscode/
/.docker/
/flask/__pycache__/
/flask/.env
/flask/vercel.json
/flask/static/
/flask/.vercel
/frontend/node_modules/
tests/__pycache__/

# backend
/backend/.env
/backend/vercel.json
/backend/static/*.tar.gz
/backend/__pycache__/
/backend/tests/__pycache__/
/backend/.vercel
/backend/app.log
/.DS_Store
/flask/.DS_Store
/backend/.DS_Store

# dependencies
/frontend/node_modules
/frontend//.pnp
/frontend/.pnp.js

# testing
.pytest_cache/
/frontend/coverage
tests/__pycache__/

# production
/frontend/build

# misc
/frontend/.DS_Store
/frontend/.env.local
/frontend/.env.development.local
/frontend/.env.test.local
/frontend/.env.production.local

/frontend/npm-debug.log*
/frontend/yarn-debug.log*
/frontend/yarn-error.log*
66 changes: 26 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
# Registry for Fortran package manager
# Registry for Fortran Package Manager

Currently for the testing phase :
1. backend APIs are hosted at: http://registry-apis.vercel.app/
2. frontend is hosted at: https://registry-frontend.vercel.app/
3. Documentation for the APIs are available at: https://registry-apis.vercel.app/apidocs/
We are currently in the testing phase of this registry.

1. backend APIs are hosted at: https://fpm-registry.vercel.app/
2. frontend is hosted at: https://registry-phi.vercel.app/
3. Documentation for the APIs are available at: https://fpm-registry.vercel.app/apidocs/

**Please note: the current registry is a playground: its database will be fully deleted once its functionality is established. Please do not use it for production yet! more information will follow then.**

The fpm release [0.8.2](https://fortran-lang.discourse.group/t/fpm-version-0-8-2-released-centralized-registry-playground/5792) introduces fpm support for uploading packages to the fpm-registry server directly from the command-line interface, via

```
fpm publish --token <token-here>
fpm publish --token <upload-token-here>
```

fpm will now interact with a web interface that will help to manage the namespaces & packages.

fpm will now also interact with a web interface that will help to manage the namespaces & packages. detailed information regarding the fpm cli can be found here: [docs](https://fpm.fortran-lang.org/registry/index.html)

## fpm - registry : Python Flask app with Nginx and Mongo database
## Instructions to Deploy with docker containers

backend Project structure:
```
.
├── compose.yaml
├── flask
│   ├── Dockerfile
│   ├── requirements.txt
│   └── server.py
| └── app.py
| └── auth.py
| └── mongo.py
| └── .env
└── nginx
   └── nginx.conf
$ sudo chmod 666 /var/run/docker.sock # for root access
```

## Instructions for Deploy with docker compose
## Environment variable configuration

set the environment variables in .env file in backend directory or in the docker compose file (compose.yaml). MONGO_URI must be set in the environment to the URL value of the MongoDB to use. For example,If deploying to production, MONGO_URI should be set to mongo container address. set the following env variables in the .env file in the backend folder:
- SALT
- MONGO_URI=MONGO_DB_ATLAS_UR
- MONGO_DB_NAME
- SUDO_PASSWORD
- MONGO_USER_NAME
- MONGO_PASSWORD
- HOST
- RESET_EMAIL
- RESET_PASSWORD

#### before building the docker containers, you must configure the environment variables ("RESET_EMAIL" and "RESET_PASSWORD") in the compose.yaml file .

```
$ sudo chmod 666 /var/run/docker.sock (for root access)
$ docker compose up -d
$ REACT_APP_REGISTRY_API_URL="http://127.0.0.1:9090" npm start run
$ docker compose -f "compose.yaml" up -d --build
$ cd frontend && REACT_APP_REGISTRY_API_URL="http://127.0.0.1:80" npm start run
```

After the application starts, navigate to `http://localhost:80` in your web browser or run:
Expand All @@ -50,19 +49,6 @@ $ curl localhost:80
Hello world, Mongo Flask
```

set MONGO_URI=MONGO_DB_ATLAS_URL (in .env file in flask directory)
The MONGO_URI must be set in the environment (or, alternatively, in the .env file in the flask directory) to the URL value of the MongoDB to use. For example,If deploying to production, MONGO_URI should be set to mongo container address.
set the following env variables in the .env file in the flask folder:
- SALT
- MONGO_URI
- MONGO_DB_NAME
- SUDO_PASSWORD
- MONGO_USER_NAME
- MONGO_PASSWORD
- HOST
- RESET_EMAIL
- RESET_PASSWORD

Stop and remove the containers

```
Expand Down
File renamed without changes.
13 changes: 8 additions & 5 deletions flask/auth.py → backend/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
sudo_password = os.getenv("SUDO_PASSWORD")
fortran_email = os.getenv("RESET_EMAIL")
fortran_password = os.getenv("RESET_PASSWORD")
is_ci = os.getenv("IS_CI", "false")
host = os.getenv("HOST")
IS_VERCEL = os.getenv("IS_VERCEL")
env_var["host"] = host
env_var["salt"] = salt
env_var["sudo_password"] = sudo_password
smtp = smtplib.SMTP("smtp.gmail.com", 587)
smtp.starttls()
smtp.login(fortran_email, fortran_password)
if is_ci!="true":
smtp = smtplib.SMTP("smtp.gmail.com", 587)
smtp.starttls()
smtp.login(fortran_email, fortran_password)

except KeyError as err:
print("Add SALT to .env file")
Expand Down Expand Up @@ -60,7 +63,7 @@ def login():
if not user:
return jsonify({"message": "Invalid email or password", "code": 401}), 401

if not user["isverified"]:
if not user["isverified"] and is_ci!='true': # TODO: Uncomment this line to enable email verification
return jsonify({"message": "Please verify your email", "code": 401}), 401

uuid = generate_uuid() if user["loggedCount"] == 0 else user["uuid"]
Expand Down Expand Up @@ -143,7 +146,7 @@ def signup():
else:
user["roles"] = ["user"]
db.users.insert_one(user)
send_verify_email(email)
send_verify_email(email) if is_ci != 'true' else None
return (
jsonify(
{
Expand Down
32 changes: 32 additions & 0 deletions backend/compose.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
services:
test_ci:
build:
context: .
target: builder
dockerfile: docker/backend.Dockerfile
command: python -m unittest discover -s tests
volumes:
- .:/src
depends_on:
- mongo
environment:
# these are the test environment variables.
- MONGO_DB_NAME=testregistry
- MONGO_URI=mongodb://mongo:27017/testregistry
- MONGO_USER_NAME=testuser
- MONGO_PASSWORD=testpassword
- SALT=MYSALT
- HOST=localhost
- [email protected]
- RESET_PASSWORD=reset
- SUDO_PASSWORD=SUDO_PASSWORD
- IS_CI=true

validate_package:
build:
dockerfile: docker/validate_package.Dockerfile
stop_signal: SIGINT

mongo:
image: mongo

18 changes: 9 additions & 9 deletions compose.yaml → backend/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ services:

backend:
build:
context: flask
context: .
target: builder
dockerfile: backend.Dockerfile
dockerfile: docker/backend.Dockerfile
# flask requires SIGINT to stop gracefully
# (default stop signal from Compose is SIGTERM)
stop_signal: SIGINT
Expand All @@ -28,22 +28,22 @@ services:
- SUDO_PASSWORD=fortran
- MONGO_USER_NAME=fortran
- MONGO_PASSWORD=fortran
- HOST=localhost
- [email protected]
- RESET_PASSWORD=reset
- HOST=localhost:3000
# - [email protected] # set to registry email
# - RESET_PASSWORD=reset

volumes:
- ./flask:/src
- .:/src
depends_on:
- mongo

validate_package:
build:
context: flask
dockerfile: validate_package.Dockerfile
context: .
dockerfile: docker/validate_package.Dockerfile
stop_signal: SIGINT
volumes:
- ./flask:/src
- .:/src

mongo:
image: mongo
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ USER root
WORKDIR /home/registry

# Set up fpm
RUN wget https://github.com/fortran-lang/fpm/releases/download/v0.8.0/fpm-0.8.0-linux-x86_64 -4 -O fpm && \
RUN wget https://github.com/fortran-lang/fpm/releases/download/v0.9.0/fpm-0.9.0-linux-x86_64 -4 -O fpm && \
chmod u+x fpm

WORKDIR /home/registry
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2d83cdb

Please sign in to comment.