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

task: add better intellij support for local devlopment #1937

Merged
merged 12 commits into from
Oct 3, 2023
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@ Save your configuration, and choose Debug from the Run menu. You will now hit br
The easiest way to debug the back end is to use the auto-created debug profile in IntelliJ. However first you'll have to
create a new run config to decrypt the application secrets and then modify the default run profile to include it.

1) Create a new run profile named "Decrypt" which runs the `hmiServerDev decrypt` command:
![Decrypt run config](docs/decrypt.png)
1) Create a new run profile named "start-server-ide" which runs the `./hmiServerDev start-server-ide` command:
![start-server-ide.png](docs%2Fstart-server-ide.png)
2) Navigate now to the default created Spring Boot run profile. If you don't have one, create one and set the properties to what you see below.
* Add a "Before Launch" option of "Run Another Configuration" and select the "Decrypt" run config you just created. Slot it first.
![springboot-config.png](docs%2Fspringboot-config.png)
* Add a "Before Launch > Add before launch task" option
![springboot-config-add-run-options.png](docs%2Fspringboot-config-add-run-options.png)
* Select "Run Another Configuration" and select the `start-server-ide` run config you just created. **Slot it first.**
* In the _Active profiles_ field, enter `default,secrets`
![springboot-config-active-profiles.png](docs%2Fspringboot-config-active-profiles.png)
</details>


Expand Down
1 change: 1 addition & 0 deletions containers/docker-compose-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version: '3.8'
services:
redis:
image: ghcr.io/darpa-askem/redis:7.0.12-alpine
container_name: redis
networks:
- terarium
ports:
Expand Down
Binary file removed docs/decrypt.png
Binary file not shown.
Binary file added docs/springboot-config-active-profiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/springboot-config-add-run-options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/start-server-ide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 49 additions & 18 deletions hmiServerDev.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
#!/usr/bin/env bash

# Description: This script is used to start the server locally for development purposes.
# It will decrypt the secrets file, start the server, then remove the secrets file.

SERVER_DIR="packages/server"
ENCRYPTED_FILE="src/main/resources/application-secrets.properties.encrypted"
DECRYPTED_FILE="src/main/resources/application-secrets.properties"
ENCRYPTED_FILE="${SERVER_DIR}/src/main/resources/application-secrets.properties.encrypted"
DECRYPTED_FILE="${SERVER_DIR}/src/main/resources/application-secrets.properties"
VAULT_PASSWORD=""~/askem-vault-id.txt""

function decrypt_secrets() {
echo "Decrypting local secrets vault"
ansible-vault decrypt --vault-password-file ${VAULT_PASSWORD} --output ${DECRYPTED_FILE} ${ENCRYPTED_FILE}
}

function encrypt_secrets() {
echo "Encrypting local secrets vault"
ansible-vault encrypt --vault-password-file ${VAULT_PASSWORD} --output ${ENCRYPTED_FILE} ${DECRYPTED_FILE}
}

function delete_secrets() {
echo "Deleting local secrets vault"
rm ${DECRYPTED_FILE}
}

function deploy_containers() {
echo "Deploying local containers"
docker compose --file containers/docker-compose-base.yml --project-name terarium up --detach --no-recreate --wait
}

function start_server() {
echo "Starting local server"
cd ${SERVER_DIR} || exit
gradle bootRun --args='--spring.profiles.active=default,secrets'
cd - || exit
}

case ${1} in
-h | --help)
Expand All @@ -12,6 +42,9 @@ case ${1} in
start)
COMMAND="start"
;;
start-server-ide)
COMMAND="start-server-ide"
;;
decrypt)
COMMAND="decrypt"
;;
Expand All @@ -25,29 +58,27 @@ COMMAND=${COMMAND:-"start"}

case ${COMMAND} in
start)
cd ${SERVER_DIR} || exit
echo "Decrypting local secrets vault"
ansible-vault decrypt --vault-password-file ${VAULT_PASSWORD} --output ${DECRYPTED_FILE} ${ENCRYPTED_FILE}
echo "Deploying local containers"
docker compose -f ../../containers/docker-compose-base.yml up -d
echo "Starting local server"
gradle bootRun --args='--spring.profiles.active=default,secrets'
echo "Deleting local secrets vault"
rm ${DECRYPTED_FILE}
decrypt_secrets
deploy_containers
start_server
delete_secrets
;;
start-server-ide)
decrypt_secrets
deploy_containers
;;
decrypt)
cd ${SERVER_DIR} || exit
ansible-vault decrypt --vault-password-file ${VAULT_PASSWORD} --output ${DECRYPTED_FILE} ${ENCRYPTED_FILE}
decrypt_secrets
;;
encrypt)
cd ${SERVER_DIR} || exit
ansible-vault encrypt --vault-password-file ${VAULT_PASSWORD} --output ${ENCRYPTED_FILE} ${DECRYPTED_FILE}
encrypt_secrets
;;
help)
echo "
Usage:
${0} start Decrypts the secrets file, starts the application via 'gradle bootRun', then removes secrets after run
${0} decrypt Decrypt secrets (${ENCRYPTED_FILE}) to an unencrypted file (${DECRYPTED_FILE})
${0} encrypt Encrypts ${DECRYPTED_FILE} to the checked in secrets file, ${ENCRYPTED_FILE}"
${0} start Decrypts the secrets file, starts the application via 'gradle bootRun', then removes secrets after run
${0} start-server-ide Decrypts the secrets file, starts the application via IntelliJ, then removes secrets after run
${0} decrypt Decrypt secrets (${ENCRYPTED_FILE}) to an unencrypted file (${DECRYPTED_FILE})
${0} encrypt Encrypts ${DECRYPTED_FILE} to the checked in secrets file, ${ENCRYPTED_FILE}"
;;
esac