Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate CIOOS Metadata #368

Merged
merged 43 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9a17f53
upgrade firebase.js
JessyBarrette Oct 10, 2024
fd93ba6
upgrade production config to new project firebase config
JessyBarrette Oct 16, 2024
835a075
fix databaseURL link to cioos-metadata-form-dev project
JessyBarrette Oct 22, 2024
79a08d8
remove firebase original url dependancy and refactor some of the code
JessyBarrette Oct 22, 2024
8921c05
drop setup.py
JessyBarrette Oct 22, 2024
af9dd90
add ruff dependancies for development
JessyBarrette Oct 22, 2024
06300a0
ruff format .
JessyBarrette Oct 22, 2024
81328b0
ruff check fix .
JessyBarrette Oct 22, 2024
3d73ff2
add encoding cli input
JessyBarrette Oct 22, 2024
3d95bdb
drop print line
JessyBarrette Oct 22, 2024
82eceb4
refactor call
JessyBarrette Oct 22, 2024
7c6efa5
ruff format .
JessyBarrette Oct 22, 2024
4c6f7d0
sort imports with ruff
JessyBarrette Oct 22, 2024
70007f1
add missing comma to firebase.js
JessyBarrette Oct 23, 2024
25dcf3a
update firebase projects to match new ones
JessyBarrette Oct 23, 2024
19ec7bd
update projectids
JessyBarrette Oct 23, 2024
c81d7f4
fix dev firebase config
JessyBarrette Oct 23, 2024
003d02f
set node v20
JessyBarrette Nov 1, 2024
81ef781
add .env.* and *.logs to gitgnore
JessyBarrette Nov 1, 2024
f20bae7
Revert "remove firebase original url dependancy and refactor some of …
JessyBarrette Nov 1, 2024
f9dba74
Merge pull request #367 from cioos-siooc/feature/update-firebase-to-xml
JessyBarrette Nov 1, 2024
a204681
Merge branch 'fix/firebase-to-xml' into migrate-cioos-form
JessyBarrette Nov 1, 2024
6458c1d
add json from database output
JessyBarrette Nov 1, 2024
1b4a1d5
fix json out string and mimeTypes
JessyBarrette Nov 1, 2024
fb0574d
add waf to the docker compose
JessyBarrette Nov 8, 2024
6aa1185
add script to retrieve pac_dev1 metadata
JessyBarrette Nov 8, 2024
6dc641a
fix get script
JessyBarrette Nov 8, 2024
62f8d7c
fix conf docker compose
JessyBarrette Nov 8, 2024
c8fabfb
add a status endpoint
JessyBarrette Nov 8, 2024
5fd1906
rename services
JessyBarrette Nov 8, 2024
6eaab6f
add docs to readme
JessyBarrette Nov 8, 2024
8e96c01
update links to forms waf and api
JessyBarrette Nov 8, 2024
15a53be
missing / to urlBaseDefault
JessyBarrette Nov 13, 2024
df3edb2
fix project documentation
JessyBarrette Nov 29, 2024
77f5637
return new line character readme
JessyBarrette Dec 2, 2024
74b7806
update sentry project link in readme
JessyBarrette Dec 2, 2024
1c970d8
fix storage buckets
JessyBarrette Dec 3, 2024
1ccaa13
fix comments
JessyBarrette Dec 3, 2024
6203c37
Merge remote-tracking branch 'origin/migrate-cioos-form' into migrate…
JessyBarrette Dec 4, 2024
af82f0e
add devcontainer
JessyBarrette Dec 4, 2024
d1863b3
comment local db connection while using localhost
JessyBarrette Dec 4, 2024
41a0c11
rename targets in firebase-functions/.firebaserc to match new projects
JessyBarrette Dec 4, 2024
44b3a60
add login step to readme
JessyBarrette Dec 6, 2024
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
31 changes: 31 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
{
"name": "Node.js & TypeScript",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bookworm",
"features": {
"ghcr.io/devcontainers-extra/features/firebase-cli:2": {
"version": "13.20.0"
},
"ghcr.io/devcontainers/features/java:1": {
"version": "23"
}

},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [4000,4500,5001,5002,8081,9001,9150,9099]

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
4 changes: 2 additions & 2 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"projects": {
"default": "cioos-metadata-form",
"dev": "cioos-metadata-form-dev"
"default": "cioos-metadata-form-8d942",
"dev": "cioos-metadata-form-dev-258dc"
},
"targets": {},
"etags": {}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/firebase-hosting-delete-channel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
args: hosting:channel:delete pr${{github.event.number}}-${{steps.get-short-name.outputs.id}} --force
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_ID: cioos-metadata-form-dev
PROJECT_ID: cioos-metadata-form-dev-258dc
GITHUB_AUTH: ${{ secrets.ISSUE_CREATOR_PAT }}
2 changes: 1 addition & 1 deletion .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_CIOOS_METADATA_FORM }}'
expires: 30d
entryPoint: '.'
projectId: cioos-metadata-form-dev
projectId: cioos-metadata-form-dev-258dc
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
GMAIL_USER: ${{ secrets.GMAIL_USER }}
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ firebase_to_xml/venv
*.egg-info
TODO

.devcontainer
.vscode

node_modules
Expand All @@ -39,4 +38,6 @@ firebase-debug.log
.Rproj.user

yarn.lock
.env
.env
.env.*
*.log
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This will start a hot-reloading dev server. Click on the link that it outputs to

## Monitoring

Monitoring of production site availability is done via the [cioos-upptime](https://github.com/cioos-siooc/cwatch-upptime) and notices are posted to the CIOOS cwatch-upptime slack channel. Error collection is performed by sentry and reported in the [cioos-metadata-entry-form](https://hakai-institute.sentry.io/projects/cioos-metadata-entry-form/) project.
Monitoring of production site availability is done via the [cioos-upptime](https://github.com/cioos-siooc/cwatch-upptime) and notices are posted to the CIOOS cwatch-upptime slack channel. Error collection is performed by sentry and reported in the [cioos-metadata-entry-form](https://cioos.sentry.io/projects/cioos-metadata-entry-form/) project.

### Running the Firebase emulator

Expand Down Expand Up @@ -73,17 +73,24 @@ We use a GitHub Actions workflow named `firebase-deploy` for deploying Firebase

### Deploying to Development Project

To deploy updated Firebase functions to the "cioos-metadata-form-dev" development project, follow these steps:
To deploy updated Firebase functions to the "cioos-metadata-form-dev-258dc" development project, follow these steps:

1. **Ensure your local setup is linked to the correct Firebase project** by using the Firebase CLI to login and select the "cioos-metadata-form-dev" project.
1. **Login** to firebase

```bash
firebase login
```

2. **Ensure your local setup is linked to the correct Firebase project** by using the Firebase CLI to login and select the "cioos-metadata-form-dev-258dc" project.

```bash
firebase use cioos-metadata-form-dev
firebase use cioos-metadata-form-dev-258dc
```

2. **Make necessary changes to your Firebase functions.**
3. **Make necessary changes to your Firebase functions.**

3. **Deploy the changes by running the command:**
4. **Deploy the changes by running the command:**
From the `./firebase-functions/functions` directory run the command:

```bash
firebase deploy --only functions
Expand All @@ -103,7 +110,7 @@ The workflow utilizes the following secrets to create the virtual `.env` file fo
- `GITHUB_AUTH` used to push to github pages branch and other github action type stuff
- `REACT_APP_DEV_DEPLOYMENT` used to switch between development and production databases. Default False, set to True to use Dev database
- `REACT_APP_GOOGLE_CLOUD_API_KEY` found at https://console.cloud.google.com/apis/credentials?project=cioos-metadata-form
- `REACT_APP_GOOGLE_CLOUD_API_KEY_DEV` found at https://console.cloud.google.com/apis/credentials?project=cioos-metadata-form-dev
- `REACT_APP_GOOGLE_CLOUD_API_KEY_DEV` found at https://console.cloud.google.com/apis/credentials?project=cioos-metadata-form-dev-258dc

### Using Parameterized Configuration in Firebase Functions

Expand Down Expand Up @@ -137,12 +144,12 @@ Deploying Firebase Realtime Database security rules via the Firebase CLI is reco

### Define targets

This project has two databases: `cioos-metadata-form` (this is the default/main db for production) and `cioos-metadata-form-dev` (dev).
This project has two databases: `cioos-metadata-form-8d942` (this is the default/main db for production) and `cioos-metadata-form-dev-258dc` (dev).
Use Firebase CLI targets to manage rules deployment:

```bash
firebase target:apply database prod cioos-metadata-form
firebase target:apply database dev cioos-metadata-form-dev
firebase target:apply database prod cioos-metadata-form-8d942
firebase target:apply database dev cioos-metadata-form-dev-258dc
```

### Configure firebase.json
Expand Down Expand Up @@ -188,10 +195,10 @@ When hosting the application in a new place there are a couple of things to upda

- You must add your new domain to the allowed list for authenication in firebase.
https://console.firebase.google.com/u/0/project/cioos-metadata-form/authentication/settings
https://console.firebase.google.com/u/0/project/cioos-metadata-form-dev/authentication/settings
https://console.firebase.google.com/u/0/project/cioos-metadata-form-dev-258dc/authentication/settings

- You have to allow your domain under Website restrictions for the firebase browser key
https://console.cloud.google.com/apis/credentials/key/405d637a-efd4-48f5-95c6-f0af1d7f4889?project=cioos-metadata-form
https://console.cloud.google.com/apis/credentials/key/23d360a3-4b55-43f2-bc1c-b485371c0e07?project=cioos-metadata-form-dev
https://console.cloud.google.com/apis/credentials/key/23d360a3-4b55-43f2-bc1c-b485371c0e07?project=cioos-metadata-form-dev-258dc


1 change: 1 addition & 0 deletions cioos-records-update/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ xml
key.json
deploy.sh
record.json
metadata
12 changes: 11 additions & 1 deletion cioos-records-update/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# CIOOS Records Update

This is a basic Flask app to create XML from the metadata form
Section contains all the different compontents used to synchronized the cioos catalogues with the metadata-entry-form.

Both services share the same volume of data where one generates and maintains the different forms and the second provides access to the forms.

## metadata-entry-forms-web-api
A basic Flask app to create XML from the metadata form

Requires `key.json` which contains a service account key json
specifically one from [here](https://console.cloud.google.com/iam-admin/serviceaccounts/details/108735728189650899572/keys?authuser=0&hl=en&project=cioos-metadata-form) you can also generate one [here](https://console.firebase.google.com/u/0/project/cioos-metadata-form/settings/serviceaccounts/adminsdk)

Alternatively the same service account key json string can be specified in the FIREBASE_SERVICE_ACCOUNT_KEY environment variable. The app will look for the environment variable first and fall back to the key.json file if ot found.

## metadata-entry-forms-waf

The metadata-entry-forms-waf service is used to retrieve the metadata forms generated by the metadata entry form.

7 changes: 6 additions & 1 deletion cioos-records-update/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# this is bind mounted to /var/www/html/dev/metadata
xml_folder = "xml"

waf_url = "https://pac-dev1.cioos.org/dev/metadata/"
waf_url = "https://waf.forms.cioos.ca/metadata/"
app = Flask(__name__)

def delete_record(basename):
Expand Down Expand Up @@ -63,6 +63,11 @@ def get_complete_path(status, region, basename,file_suffix):
return filename


@app.route("/status", methods=["GET"])
def status():
return jsonify(message="OK")


@app.route("/recordDelete")
def recordDelete():
filenameToDelete = request.args.get("filename")
Expand Down
19 changes: 17 additions & 2 deletions cioos-records-update/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
version: "3"
services:
web:
container_name: metadata-entry-forms-web-api
build: .
ports:
- "8091:8000"
volumes:
- /var/www/html/dev/metadata:/usr/src/app/xml
- cioos_metadata_form_files:/usr/src/app/xml
environment:
FLASK_ENV: production
restart: always
waf:
image: nginx:alpine
container_name: metadata-entry-forms-waf
ports:
- "8092:80"
volumes:
- ./waf/nginx.conf:/etc/nginx/conf.d/default.conf
- ./waf/header.html:/usr/share/nginx/html/files/header.txt
- ./waf/footer.html:/usr/share/nginx/html/files/footer.txt
- cioos_metadata_form_files:/usr/share/nginx/html/metadata:ro

volumes:
cioos_metadata_form_files:
external: true
name: cioos-metadata-form-files
2 changes: 2 additions & 0 deletions cioos-records-update/get_pac_dev1_metadata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
wget --no-parent -r "https://pac-dev1.cioos.org/dev/metadata" -A ".xml" -A ".yaml"
28 changes: 28 additions & 0 deletions cioos-records-update/save_metadata_to_volume.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Check if the folder to be copied is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 /path/to/local/folder"
exit 1
fi

# Define the folder to be copied and the volume name
FOLDER_TO_COPY=$1
VOLUME_NAME="cioos-metadata-form-files"

# if the volume exists remove its content
if docker volume inspect ${VOLUME_NAME} &> /dev/null; then
echo "Volume ${VOLUME_NAME} exists. Removing its content..."
docker run --rm -v ${VOLUME_NAME}:/data busybox rm -rf /data/*
fi

# Create a temporary container with the volume mounted
TEMP_CONTAINER=$(docker run -d -v ${VOLUME_NAME}:/data busybox sleep 3600)

# Copy the folder to the volume
docker cp ${FOLDER_TO_COPY} ${TEMP_CONTAINER}:/data

# Stop and remove the temporary container
docker rm -f ${TEMP_CONTAINER}

echo "Folder ${FOLDER_TO_COPY} has been copied to the Docker volume ${VOLUME_NAME}."
3 changes: 3 additions & 0 deletions cioos-records-update/waf/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
</ul>
</body>
</html>
36 changes: 36 additions & 0 deletions cioos-records-update/waf/header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Directory Listing</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
h1 {
color: #333;
}
ul {
list-style-type: none;
padding: 0;
}
li {
margin: 5px 0;
}
a {
text-decoration: none;
color: #007bff;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>CIOOS Metadata Forms</h1>
This page present the list of metadata forms generated by the <a href="https://cioos-siooc.github.io/metadata-entry-form/#/en/region-select">cioos metadata forms</a> .
<ul>
18 changes: 18 additions & 0 deletions cioos-records-update/waf/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
server {
listen 80;
server_name localhost;

location / {
alias /usr/share/nginx/html/;
autoindex on;
autoindex_exact_size off;
autoindex_localtime off;
index index.html;
add_before_body /files/header.txt;
add_after_body /files/footer.txt;
types {
text/plain yaml;
text/xml xml;
}
}
}
16 changes: 8 additions & 8 deletions firebase-functions/.firebaserc
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"projects": {
"default": "cioos-metadata-form",
"dev": "cioos-metadata-form-dev"
"default": "cioos-metadata-form-8d942",
"dev": "cioos-metadata-form-dev-258dc"
},
"targets": {
"cioos-metadata-form": {
"cioos-metadata-form-8d942": {
"database": {
"prod": [
"cioos-metadata-form"
"cioos-metadata-form-8d942"
],
"dev": [
"cioos-metadata-form-dev"
"cioos-metadata-form-dev-258dc"
]
}
},
"development": {
"cioos-metadata-form-dev-258dc": {
"database": {
"prod": [
"cioos-metadata-form"
"cioos-metadata-form-258dc"
],
"dev": [
"cioos-metadata-form-dev"
"cioos-metadata-form-dev-258dc"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion firebase-functions/functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion firebase-functions/functions/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const functions = require("firebase-functions");
const https = require("https");
const axios = require("axios");

const urlBaseDefault = "https://pac-dev1.cioos.org/cioos-xml/"
const urlBaseDefault = "https://api.forms.cioos.ca/"

function getRecordFilename(record) {
return `${record.title[record.language].slice(
Expand Down
1 change: 1 addition & 0 deletions firebase_to_xml/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
Loading
Loading