Skip to content

Commit

Permalink
Merge pull request #356 from systemaccounting/dev-integration
Browse files Browse the repository at this point in the history
dev-integration workflow
  • Loading branch information
mxfactorial authored Apr 14, 2024
2 parents 6746036 + 44db4e0 commit 27f4a0e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/dev-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ jobs:
rm migrate.linux-amd64.deb
- name: deploy to dev cloud environment
run: |
for app in $(echo $(bash scripts/list-dir-paths.sh --type app | grep -v client) | xargs basename); do
for app in $(bash scripts/list-dir-paths.sh --type app | grep -v client | xargs basename -a); do
# tag newly pushed dev images with develop merge commit sha
bash scripts/tag-merge-commit.sh --app-name $app --env dev --env-id ${{ secrets.DEV_ENV_ID }};
# deploy newly tagged images to dev cloud
bash scripts/deploy-last-image.sh --app-name $app --env dev --env-id ${{ secrets.DEV_ENV_ID }};
done
- name: reset rds database for integration tests
run: make --no-print-directory -C ./migrations resetrds ENV=dev DB=test
run: ENV_ID=${{ secrets.DEV_ENV_ID }} make --no-print-directory -C ./migrations resetrds ENV=dev DB=test
- name: dump rds database locally for restore between integration tests
run: make --no-print-directory -C ./migrations/dumps dump-rds-testseed
- name: get secrets for dev integration tests
run: make --no-print-directory -C ./tests get-secrets ENV=dev
run: ENV_ID=${{ secrets.DEV_ENV_ID }} make --no-print-directory -C ./tests get-secrets ENV=dev
- name: run dev cloud integration tests
run: cargo test --manifest-path ./tests/Cargo.toml --features integration_tests -- --test-threads=1
run: ENV_ID=${{ secrets.DEV_ENV_ID }} cargo test --manifest-path ./tests/Cargo.toml --features integration_tests -- --test-threads=1
- name: tag and push dev images to prod ecr
run: |
for app in $(echo $(bash scripts/list-dir-paths.sh --type app | grep -v client) | xargs basename); do
for app in $(bash scripts/list-dir-paths.sh --type app | grep -v client | xargs basename -a); do
# tag newly tested dev images with prod and push to prod ecr
bash scripts/push-prod-image.sh --app-name $app --env dev --env-id ${{ secrets.DEV_ENV_ID }};
done
2 changes: 1 addition & 1 deletion .github/workflows/prod-services-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run: echo "::add-mask::${{ secrets.AWS_ACCOUNT_ID }}"
- name: deploy services to prod cloud environment
run: |
for app in $(echo $(bash scripts/list-dir-paths.sh --type app | grep -v client) | xargs basename); do
for app in $(bash scripts/list-dir-paths.sh --type app | grep -v client | xargs basename -a); do
# tag newly pushed prod images with master merge commit sha
bash scripts/tag-merge-commit.sh --app-name $app --env prod --env-id ${{ secrets.PROD_ENV_ID }};
# deploy newly tagged images to prod cloud
Expand Down
6 changes: 2 additions & 4 deletions migrations/dumps/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ dump-testseed:
bash scripts/dump-db.sh

restore-testseed:
$(MAKE) -C '..' downdocker DB=test # drops functions
$(MAKE) -C '..' dropdocker DB=test # drops migration tables
$(MAKE) -C '..' dropdocker DB=test
@cd $(RELATIVE_PROJECT_ROOT_PATH); \
bash scripts/restore-db.sh

Expand All @@ -15,7 +14,6 @@ dump-rds-testseed:
bash scripts/dump-db.sh --rds

restore-rds-testseed:
$(MAKE) -C '..' downrds DB=test # drops functions
$(MAKE) -C '..' droprds DB=test # drops migration tables
$(MAKE) -C '..' droprds DB=test
@cd $(RELATIVE_PROJECT_ROOT_PATH); \
bash scripts/restore-db.sh --rds
2 changes: 1 addition & 1 deletion scripts/delete-ecr-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ENV=dev
ENV_ID=$(source scripts/print-env-id.sh)
REGION=$(yq '.infrastructure.terraform.aws.modules.environment.env_var.set.REGION.default' $PROJECT_CONF)

for APP_NAME in $(echo $(bash scripts/list-dir-paths.sh --type app | grep -v client) | xargs basename); do
for APP_NAME in $(bash scripts/list-dir-paths.sh --type app | grep -v client | xargs basename -a); do
IMAGE_NAME="$ENV_ID/$ENV/$APP_NAME"
aws ecr delete-repository --repository-name $IMAGE_NAME --region $REGION --force
done
24 changes: 20 additions & 4 deletions tests/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use serde_json::json;
use std::{env, fs::File, io::BufReader, process::Command};

pub fn restore_testseed() {
// cloud dev env
if env::var("AWS_LAMBDA_FUNCTION_NAME").ok().is_some() {
let restore_output = Command::new("make")
.arg("--no-print-directory")
.arg("-C")
.arg("../migrations/dumps")
.arg("restore-rds-testseed")
Expand All @@ -18,19 +20,33 @@ pub fn restore_testseed() {
.expect("failed to execute process");

// cargo test -- --show-output
let restore_output_str = String::from_utf8(restore_output.stdout).expect("Not UTF8");
println!("{}", restore_output_str);
if !restore_output.clone().stderr.is_empty() {
let restore_output_str = String::from_utf8(restore_output.stderr).expect("Not UTF8");
println!("{}", restore_output_str);
}
if !restore_output.stdout.is_empty() {
let _restore_output_str = String::from_utf8(restore_output.stdout).expect("Not UTF8");
// println!("{}", _restore_output_str);
}
} else {
// local env
let restore_output = Command::new("make")
.arg("--no-print-directory")
.arg("-C")
.arg("../migrations/dumps")
.arg("restore-testseed")
.output()
.expect("failed to execute process");

// cargo test -- --show-output
let _restore_output_str = String::from_utf8(restore_output.stdout).expect("Not UTF8");
// println!("{}", _restore_output_str); // comment in to print db restore output
if !restore_output.clone().stderr.is_empty() {
let restore_output_str = String::from_utf8(restore_output.stderr).expect("Not UTF8");
println!("{}", restore_output_str);
}
if !restore_output.stdout.is_empty() {
let _restore_output_str = String::from_utf8(restore_output.stdout).expect("Not UTF8");
// println!("{}", _restore_output_str); // comment in to print db restore output
}
}
}

Expand Down

0 comments on commit 27f4a0e

Please sign in to comment.