Add hotfix for updating org slug
This commit is contained in:
parent
ffc60e45f8
commit
62006a09ed
@ -49,12 +49,25 @@ export class Database {
|
|||||||
await this.dataSource.initialize();
|
await this.dataSource.initialize();
|
||||||
log('database initialized');
|
log('database initialized');
|
||||||
|
|
||||||
const organizations = await this.getOrganizations({});
|
let organizations = await this.getOrganizations({});
|
||||||
|
|
||||||
// Load an organization if none exist
|
// Load an organization if none exist
|
||||||
if (!organizations.length) {
|
if (!organizations.length) {
|
||||||
const orgEntities = await getEntities(path.resolve(__dirname, ORGANIZATION_DATA_PATH));
|
const orgEntities = await getEntities(path.resolve(__dirname, ORGANIZATION_DATA_PATH));
|
||||||
await loadAndSaveData(Organization, this.dataSource, [orgEntities[0]]);
|
organizations = await loadAndSaveData(Organization, this.dataSource, [orgEntities[0]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hotfix for updating old DB data
|
||||||
|
if (organizations[0].slug === 'snowball-tools-1') {
|
||||||
|
const [orgEntity] = await getEntities(path.resolve(__dirname, ORGANIZATION_DATA_PATH));
|
||||||
|
|
||||||
|
await this.updateOrganization(
|
||||||
|
organizations[0].id,
|
||||||
|
{
|
||||||
|
slug: orgEntity.slug as string,
|
||||||
|
name: orgEntity.name as string
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +134,14 @@ export class Database {
|
|||||||
return newUserOrganization;
|
return newUserOrganization;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateOrganization(organizationId: string, data: DeepPartial<Organization>): Promise<boolean> {
|
||||||
|
const organizationRepository = this.dataSource.getRepository(Organization);
|
||||||
|
const updateResult = await organizationRepository.update({ id: organizationId }, data);
|
||||||
|
assert(updateResult.affected);
|
||||||
|
|
||||||
|
return updateResult.affected > 0;
|
||||||
|
}
|
||||||
|
|
||||||
async getProjects(options: FindManyOptions<Project>): Promise<Project[]> {
|
async getProjects(options: FindManyOptions<Project>): Promise<Project[]> {
|
||||||
const projectRepository = this.dataSource.getRepository(Project);
|
const projectRepository = this.dataSource.getRepository(Project);
|
||||||
const projects = await projectRepository.find(options);
|
const projects = await projectRepository.find(options);
|
||||||
|
@ -8,8 +8,11 @@ echo "Using AUTHORITY: $AUTHORITY"
|
|||||||
# Repository URL
|
# Repository URL
|
||||||
REPO_URL="https://git.vdb.to/cerc-io/snowballtools-base"
|
REPO_URL="https://git.vdb.to/cerc-io/snowballtools-base"
|
||||||
|
|
||||||
# Get the latest commit hash from the repository
|
# Get the latest commit hash for a branch
|
||||||
LATEST_HASH=$(git ls-remote $REPO_URL HEAD | awk '{print $1}')
|
BRANCH_NAME="main"
|
||||||
|
LATEST_HASH=$(git ls-remote $REPO_URL refs/heads/$BRANCH_NAME | awk '{print $1}')
|
||||||
|
|
||||||
|
echo "Latest commit hash for branch $BRANCH_NAME: $LATEST_HASH"
|
||||||
|
|
||||||
# Extract version from ../frontend/package.json
|
# Extract version from ../frontend/package.json
|
||||||
PACKAGE_VERSION=$(jq -r '.version' ../frontend/package.json)
|
PACKAGE_VERSION=$(jq -r '.version' ../frontend/package.json)
|
||||||
|
57
packages/deployer/remove-deployment.sh
Executable file
57
packages/deployer/remove-deployment.sh
Executable file
@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source .env
|
||||||
|
echo "Using REGISTRY_BOND_ID: $REGISTRY_BOND_ID"
|
||||||
|
echo "Using DEPLOYER_LRN: $DEPLOYER_LRN"
|
||||||
|
|
||||||
|
# Generate application-deployment-removal-request.yml
|
||||||
|
REMOVAL_REQUEST_RECORD_FILE=records/application-deployment-removal-request.yml
|
||||||
|
# TODO: Pass deployment record ID as arg
|
||||||
|
DEPLOYMENT_RECORD_ID=bafyreidjho77xeczaqpyawhc4wbpm5it5atibtuxk6ost6vnpu2svlp3ka
|
||||||
|
|
||||||
|
cat > $REMOVAL_REQUEST_RECORD_FILE <<EOF
|
||||||
|
record:
|
||||||
|
deployer: $DEPLOYER_LRN
|
||||||
|
deployment: $DEPLOYMENT_RECORD_ID
|
||||||
|
type: ApplicationDeploymentRemovalRequest
|
||||||
|
version: 1.0.0
|
||||||
|
EOF
|
||||||
|
|
||||||
|
CONFIG_FILE=config.yml
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
REMOVAL_REQUEST_ID=$(yarn --silent laconic -c $CONFIG_FILE registry record publish --filename $REMOVAL_REQUEST_RECORD_FILE | jq -r '.id')
|
||||||
|
echo "ApplicationDeploymentRemovalRequest published"
|
||||||
|
echo $REMOVAL_REQUEST_ID
|
||||||
|
|
||||||
|
# Deployment checks
|
||||||
|
RETRY_INTERVAL=30
|
||||||
|
MAX_RETRIES=20
|
||||||
|
|
||||||
|
# Check that an ApplicationDeploymentRemovalRecord is published
|
||||||
|
retry_count=0
|
||||||
|
while true; do
|
||||||
|
removal_records_response=$(yarn --silent laconic -c $CONFIG_FILE registry record list --type ApplicationDeploymentRemovalRecord --all request $REMOVAL_REQUEST_ID)
|
||||||
|
len_removal_records=$(echo $removal_records_response | jq 'length')
|
||||||
|
|
||||||
|
# Check if number of records returned is 0
|
||||||
|
if [ $len_removal_records -eq 0 ]; then
|
||||||
|
# Check if retries are exhausted
|
||||||
|
if [ $retry_count -eq $MAX_RETRIES ]; then
|
||||||
|
echo "Retries exhausted"
|
||||||
|
echo "ApplicationDeploymentRemovalRecord for deployment removal request $REMOVAL_REQUEST_ID not found"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "ApplicationDeploymentRemovalRecord not found, retrying in $RETRY_INTERVAL sec..."
|
||||||
|
sleep $RETRY_INTERVAL
|
||||||
|
retry_count=$((retry_count+1))
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "ApplicationDeploymentRemovalRecord found"
|
||||||
|
REMOVAL_RECORD_ID=$(echo $removal_records_response | jq -r '.[0].id')
|
||||||
|
echo $REMOVAL_RECORD_ID
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Deployment removal successful"
|
Loading…
Reference in New Issue
Block a user