Skip to content

Commit

Permalink
chore: volume typo
Browse files Browse the repository at this point in the history
  • Loading branch information
amber committed Oct 27, 2024
1 parent f924e76 commit 9270df1
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 20 deletions.
54 changes: 40 additions & 14 deletions encrypt.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash
# Check if the passphrase file exists

# Define passphrase file, S3 bucket, services directory, and envs directory
PASSPHRASE_FILE="nshm.passphrase"
S3_BUCKET="s3://nus-backend-terraform"
SERVICES_DIR="services"
ENVS_DIR="envs"

# Check if the passphrase file exists; download from S3 if not
if [ ! -f "$PASSPHRASE_FILE" ]; then
echo "Passphrase file not found, downloading from S3..."
aws s3 cp "${S3_BUCKET}/${PASSPHRASE_FILE}" .
Expand All @@ -14,25 +18,47 @@ if [ ! -f "$PASSPHRASE_FILE" ]; then
else
echo "Passphrase file already exists."
fi
# Get a list of service directories
service_dirs=($(ls -d "$SERVICES_DIR"/*))
# Loop through each service directory and encrypt its .env file


# Function to encrypt a single .env file
encrypt_env_file() {
local env_file=$1
local service_name=$2
echo "Encrypting $env_file..."

# Encrypt the .env file, outputting to the encrypted_envs directory
gpg --batch --yes --passphrase-file "$PASSPHRASE_FILE" --symmetric --output "$ENVS_DIR/${service_name}.env.gpg" "$env_file"

# Check if encryption was successful
if [ $? -eq 0 ]; then
echo "$env_file encrypted successfully and saved as $ENVS_DIR/${service_name}.env.gpg"
else
echo "Failed to encrypt $env_file for $service_name. Exiting..."
exit 1
fi
}

# Encrypt .env files within subdirectories of services
service_dirs=($(ls -d "$SERVICES_DIR"/*/))
for service_dir in "${service_dirs[@]}"; do
SERVICE_NAME=$(basename "$service_dir")
ENV_FILE="$service_dir/.env"
# Check if .env file exists
if [ -f "$ENV_FILE" ]; then
echo "Encrypting $ENV_FILE..."
gpg --batch --yes --passphrase-file "$PASSPHRASE_FILE" --symmetric --output "envs/$SERVICE_NAME.env.gpg" "$ENV_FILE"
if [ $? -eq 0 ]; then
echo "$ENV_FILE encrypted successfully and moved to envs/$SERVICE_NAME.env.gpg"
else
echo "Failed to encrypt $ENV_FILE for $SERVICE_NAME. Exiting..."
exit 1
fi
encrypt_env_file "$ENV_FILE" "$SERVICE_NAME"
else
echo "No .env file found in $service_dir, skipping..."
fi
done
echo "All services processed."

# Encrypt .env files in the envs directory
for env_file in "$ENVS_DIR"/*.env; do
if [ -f "$env_file" ]; then
SERVICE_NAME=$(basename "$env_file" .env)
encrypt_env_file "$env_file" "$SERVICE_NAME"
else
echo "No .env files found in $ENVS_DIR."
fi
done

echo "All .env files processed and encrypted."

3 changes: 2 additions & 1 deletion envs/account-postgres.env.gpg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
� ��(҂A�=�ҋ6Յ<� ��/��B�������翓�5��o���,�t�G�~�<�+��Y�T�/�X�:5�VT�ok�v+���2�(�"}bA�F�8'�BAc� �ZŠAV^��t�h��H�du��D�K�۵��`���Na�4�h
� �E�^f���ҋ�s�~���B1zL8&]^~�&9PZ�������cU��ats�p�Y�CK���&e1d����s�s/Q�6�����^)mza���R1m�6؀��RWH�
���>KJ�K�h�K�Z^\��su�Bg��c��d�a7�
Expand Down
Binary file modified envs/account.env.gpg
Binary file not shown.
Binary file modified envs/currency.env.gpg
Binary file not shown.
Binary file modified envs/ec2.env.gpg
Binary file not shown.
Binary file modified envs/item-mongo.env.gpg
Binary file not shown.
Binary file modified envs/item.env.gpg
Binary file not shown.
Binary file modified envs/notification.env.gpg
Binary file not shown.
Binary file modified envs/rabbitmq.env.gpg
Binary file not shown.
3 changes: 2 additions & 1 deletion envs/web.env.gpg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
� =:���7 ���p[(S�q!d�Fr���G�+�+R;)@{�C+���F�H��InT;ۈ�p���Re}��]*��h��z�"���+��9�I~Ⱥ����p��B�ڶ��=.�U�]GT� V
� �*�6�_��p����Xby���%��!�2ݚ�@⑤�8�|; ��zS��v���N��=x����?a��
H�=q~w��������^����\�qGI�-�)UW��L!�q�9�$��9�
Expand Down
5 changes: 2 additions & 3 deletions envs/wishlist-mongo.env.gpg
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
� ���]��u0�ҟ���k����jH�윍<�0u$O��@(��k��Ny75�������=F��*�`�޾��Z��ͣ�I��P\�t�����&qjl�n�j;�M��>�x)��tdwZ�[6���
��S#[�R���pZH%:o��9n�;F�� �
6��A�>��;���
� ֒�?�(�ҟt�~�7�>TI�T����R�85y�uIZ��Xz��'~Y�m����3_>����g|Dԩ
���0y}�,ir�⋕��w��:�7&u��C��� ��O�Y��k�Q�<�G^ygщ�/ "3<>���e�lp�ܫ���К�����q�mS�K
Expand Down
Binary file modified envs/wishlist.env.gpg
Binary file not shown.
2 changes: 1 addition & 1 deletion helm/nshm/templates/wishlist-mongo/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ spec:
volumeMounts:
- name: init-script
mountPath: /docker-entrypoint-initdb.d
subPath: services/wishlist/database/prod
subPath: services/wishlist/database/production

volumes:
- name: init-script
Expand Down

0 comments on commit 9270df1

Please sign in to comment.