Skip to content

Commit

Permalink
Merge branch 'main' into TYLERB/APPEALS-APPEALS-59606
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerBroyles authored Sep 30, 2024
2 parents b40ed5a + c231266 commit 4c24ad1
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile.example
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ seed-dbs: ## Seed all databases
bundle exec rake spec:setup_vacols
bundle exec rake db:seed

setup-metabase:
./metabase/metabase_api_script.sh

enable-feature-flags: ## enable all feature flags
bundle exec rails runner scripts/enable_features_dev.rb

Expand Down
3 changes: 3 additions & 0 deletions docker-bin/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ bundle exec rails runner scripts/enable_features_dev.rb
echo "Enabling caching"
touch tmp/caching-dev.txt

echo "Initializing metabase"
/caseflow/metabase/metabase_api_script_demo.sh

echo "Starting Caseflow App RoR"
rails server --binding 0.0.0.0 -p 3000
8 changes: 8 additions & 0 deletions docker-compose-m1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@ services:
volumes:
- ./local/sqs/conf:/conf

appeals-metabase:
platform: linux/amd64
container_name: metabase
build:
context: metabase
ports:
- "3002:3000"

volumes:
postgresdata:
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@ services:
volumes:
- ./local/sqs/conf:/conf

appeals-metabase:
container_name: metabase
build:
context: metabase
ports:
- "3002:3000"

volumes:
postgresdata:
14 changes: 14 additions & 0 deletions metabase/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM metabase/metabase:v0.50.21
MAINTAINER BID Appeals

ENV MB_PLUGINS_DIR /app/plugins

WORKDIR /app
RUN addgroup --gid 2000 --system metabase
RUN adduser --disabled-password -u 2000 --ingroup metabase metabase
RUN mkdir plugins && chmod g-w plugins
RUN cd plugins && curl -sLO https://download.oracle.com/otn-pub/otn_software/jdbc/235/ojdbc8.jar

RUN chown -R metabase:metabase /app/plugins

ENTRYPOINT ["/app/run_metabase.sh"]
82 changes: 82 additions & 0 deletions metabase/metabase_api_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/sh

ADMIN_EMAIL=admin@caseflow.demo
ADMIN_PASSWORD=caseflow1
USER_EMAIL=caseflow@caseflow.demo
USER_PASSWORD=caseflow1

CASEFLOW_HOST=appeals-db
VACOLS_HOST=host.docker.internal

echo "⌚︎ Waiting for Metabase to start"
while (! curl -s -m 5 http://localhost:3002/api/session/properties -o /dev/null); do sleep 5; done

echo "😎 Creating admin user"

SETUP_TOKEN=$(curl -s -m 5 -X GET \
-H "Content-Type: application/json" \
http://localhost:3002/api/session/properties \
| jq -r '.["setup-token"]'
)

MB_TOKEN=$(curl -s -X POST \
-H "Content-type: application/json" \
http://localhost:3002/api/setup \
-d '{
"token": "'${SETUP_TOKEN}'",
"user": {
"email": "'${ADMIN_EMAIL}'",
"first_name": "Caseflow",
"last_name": "Admin",
"password": "'${ADMIN_PASSWORD}'"
},
"prefs": {
"allow_tracking": false,
"site_name": "Caseflow"
}
}' | jq -r '.id')

echo "Logging in as admin"
ADMIN_SESSION_ID=$(curl -s -X POST -H \
"Content-type: application/json" http://localhost:3002/api/session \
-d '{"username": "'${ADMIN_EMAIL}'", "password": "'${ADMIN_PASSWORD}'"}' \
| jq -r '.id')

echo "Getting Sample Database ID"
SAMPLE_DB_ID=$(curl -X GET http://localhost:3002/api/database -H "X-Metabase-Session: ${ADMIN_SESSION_ID}" \
| jq '.data[0].id')

echo "Deleting Sample Database"
curl -X DELETE http://localhost:3002/api/database/${SAMPLE_DB_ID} -H "X-Metabase-Session: ${ADMIN_SESSION_ID}"

echo "Creating Caseflow Database connection"
curl -X POST http://localhost:3002/api/database \
-H "Content-type: application/json" \
-H "X-Metabase-Session: ${ADMIN_SESSION_ID}" \
-d '{
"engine": "postgres",
"name": "Caseflow DB",
"details": {
"host": "'${CASEFLOW_HOST}'", "port":"5432", "db": "caseflow_certification_development", "user": "postgres", "password": "postgres"
}
}'

echo -e "\nCreating VACOLS Database connection"
curl -X POST http://localhost:3002/api/database \
-H "Content-type: application/json" \
-H "X-Metabase-Session: ${ADMIN_SESSION_ID}" \
-d '{
"engine": "oracle",
"name": "VACOLS",
"details": {
"host": "'${VACOLS_HOST}'", "port": "1521", "sid": "BVAP", "name": "VACOLS_DEV", "user": "VACOLS_DEV", "password": "VACOLS_DEV"
}
}'

echo -e "\n👥 Creating a basic user: "
curl -s "http://localhost:3002/api/user" \
-H 'Content-Type: application/json' \
-H "X-Metabase-Session: ${ADMIN_SESSION_ID}" \
-d '{"first_name": "Caseflow", "last_name": "User", "email": "'${USER_EMAIL}'", "login_attributes": {"region_filter": "WA"}, "password":"'${USER_PASSWORD}'"}'

echo -e "\nMetabase setup complete!"
90 changes: 90 additions & 0 deletions metabase/metabase_api_script_demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/sh

ADMIN_EMAIL=admin@caseflow.demo
ADMIN_PASSWORD=caseflow1
USER_EMAIL=caseflow@caseflow.demo
USER_PASSWORD=caseflow1

CASEFLOW_HOST=appeals-db
# The Metabase port needs to be 3000 because this will run in the appeals-app container in AWS and the port mapping
# in docker-compose is for the host only
METABASE_HOST=appeals-metabase
METABASE_PORT=3000
VACOLS_HOST=VACOLS_DB-development

echo "Installing JQ"
apt-get update
apt-get install -y jq

echo "Waiting for Metabase to start"
while (! curl -s -m 5 http://${METABASE_HOST}:${METABASE_PORT}/api/session/properties -o /dev/null); do sleep 5; done

echo "Creating admin user"

SETUP_TOKEN=$(curl -s -m 5 -X GET \
-H "Content-Type: application/json" \
http://${METABASE_HOST}:${METABASE_PORT}/api/session/properties \
| jq -r '.["setup-token"]'
)

MB_TOKEN=$(curl -s -X POST \
-H "Content-type: application/json" \
http://${METABASE_HOST}:${METABASE_PORT}/api/setup \
-d '{
"token": "'${SETUP_TOKEN}'",
"user": {
"email": "'${ADMIN_EMAIL}'",
"first_name": "Caseflow",
"last_name": "Admin",
"password": "'${ADMIN_PASSWORD}'"
},
"prefs": {
"allow_tracking": false,
"site_name": "Caseflow"
}
}' | jq -r '.id')

echo "Logging in as admin"
ADMIN_SESSION_ID=$(curl -s -X POST -H \
"Content-type: application/json" http://${METABASE_HOST}:${METABASE_PORT}/api/session \
-d '{"username": "'${ADMIN_EMAIL}'", "password": "'${ADMIN_PASSWORD}'"}' \
| jq -r '.id')

echo "Getting Sample Database ID"
SAMPLE_DB_ID=$(curl -X GET http://${METABASE_HOST}:${METABASE_PORT}/api/database -H "X-Metabase-Session: ${ADMIN_SESSION_ID}" \
| jq '.data[0].id')

echo "Deleting Sample Database"
curl -X DELETE http://${METABASE_HOST}:${METABASE_PORT}/api/database/${SAMPLE_DB_ID} -H "X-Metabase-Session: ${ADMIN_SESSION_ID}"

echo "Creating Caseflow Database connection"
curl -X POST http://${METABASE_HOST}:${METABASE_PORT}/api/database \
-H "Content-type: application/json" \
-H "X-Metabase-Session: ${ADMIN_SESSION_ID}" \
-d '{
"engine": "postgres",
"name": "Caseflow DB",
"details": {
"host": "'${CASEFLOW_HOST}'", "port":"5432", "db": "caseflow_certification_development", "user": "postgres", "password": "postgres"
}
}'

echo -e "\nCreating VACOLS Database connection"
curl -X POST http://${METABASE_HOST}:${METABASE_PORT}/api/database \
-H "Content-type: application/json" \
-H "X-Metabase-Session: ${ADMIN_SESSION_ID}" \
-d '{
"engine": "oracle",
"name": "VACOLS",
"details": {
"host": "'${VACOLS_HOST}'", "port": "1521", "sid": "BVAP", "name": "VACOLS_DEV", "user": "VACOLS_DEV", "password": "VACOLS_DEV"
}
}'

echo -e "\nCreating a basic user: "
curl -s "http://${METABASE_HOST}:${METABASE_PORT}/api/user" \
-H 'Content-Type: application/json' \
-H "X-Metabase-Session: ${ADMIN_SESSION_ID}" \
-d '{"first_name": "Caseflow", "last_name": "User", "email": "'${USER_EMAIL}'", "login_attributes": {"region_filter": "WA"}, "password":"'${USER_PASSWORD}'"}'

echo -e "\nMetabase setup complete!"

0 comments on commit 4c24ad1

Please sign in to comment.