UNCLASSIFIED - NO CUI

Skip to content
Snippets Groups Projects
Commit 66322968 authored by Peter Sigur's avatar Peter Sigur
Browse files

Merge branch 'add-sandbox-to-dev' into 'main'

Add Sandbox package option to dev script

See merge request !55
parents d02d79f9 60e343ea
No related branches found
No related tags found
1 merge request!55Add Sandbox package option to dev script
Pipeline #3955771 passed
......@@ -48,6 +48,13 @@ export KUBECONFIG=~/.kube/$(aws sts get-caller-identity --query "Arn" --output t
13. Do your dev work. Trigger new renovate pipeline runs from the pipeline schedule.
## Importing Sandbox Packages
If you would like to import/test against [Sandbox packages](https://repo1.dso.mil/big-bang/apps/sandbox) *instead* of fully supported Big Bang packages, run the script in Step #6 with the `-s` flag:
```
./dev/renovate-dev.sh -s
```
## Destroy
If you need to destroy the Renovate Dev Setup you can use the following:
```
......
......@@ -52,13 +52,16 @@ handle_curl_response() {
}
# Parse command-line options
while getopts "d" opt; do
while getopts "ds" opt; do
case ${opt} in
d)
destroy_mode=true
;;
s)
sandbox_mode=true
;;
*)
echo "Usage: $0 [-d]"
echo "Usage: $0 [-d] [-s]"
exit 1
;;
esac
......@@ -260,7 +263,7 @@ response_body=$(gum spin --show-error --spinner dot --title "Importing Renovate
sleep 30; \
curl --silent --write-out \"HTTPSTATUS:%{http_code}\" --request POST --header \"PRIVATE-TOKEN: $ROOT_TOKEN\" \
--header \"Content-Type: application/json\" \
--data \"{\\\"name\\\": \\\"renovate-runner\\\", \\\"path\\\": \\\"renovate-runner\\\", \\\"namespace_id\\\": $PIPELINES_GROUP_ID, \\\"visibility\\\": \\\"public\\\", \\\"import_url\\\": \\\"https://repo1.dso.mil/big-bang/pipeline-templates/renovate-runner.git\\\"}\" \
--data '{\"name\": \"renovate-runner\", \"path\": \"renovate-runner\", \"namespace_id\": $PIPELINES_GROUP_ID, \"visibility\": \"public\", \"import_url\": \"https://repo1.dso.mil/big-bang/pipeline-templates/renovate-runner.git\"}' \
\"$GITLAB_URL/api/v4/projects\"")
response_status=$(echo "$response_body" | grep -o 'HTTPSTATUS:[0-9]\{3\}' | cut -d':' -f2)
handle_curl_response "$response_status" "Renovate Runner Repo imported successfully" 201
......@@ -271,7 +274,7 @@ sleep 20
response_body=$(gum spin --show-error --spinner dot --title "Importing Pipeline Templates Repo.." -- bash -c "
curl --silent --write-out \"HTTPSTATUS:%{http_code}\" --request POST --header \"PRIVATE-TOKEN: $ROOT_TOKEN\" \
--header \"Content-Type: application/json\" \
--data \"{\\\"name\\\": \\\"Pipeline Templates\\\", \\\"path\\\": \\\"pipeline-templates\\\", \\\"namespace_id\\\": $PIPELINES_GROUP_ID, \\\"visibility\\\": \\\"public\\\", \\\"import_url\\\": \\\"https://repo1.dso.mil/big-bang/pipeline-templates/pipeline-templates.git\\\"}\" \
--data '{\"name\": \"Pipeline Templates\", \"path\": \"pipeline-templates\", \"namespace_id\": $PIPELINES_GROUP_ID, \"visibility\": \"public\", \"import_url\": \"https://repo1.dso.mil/big-bang/pipeline-templates/pipeline-templates.git\"}' \
\"$GITLAB_URL/api/v4/projects\"")
response_status=$(echo "$response_body" | grep -o 'HTTPSTATUS:[0-9]\{3\}' | cut -d':' -f2)
handle_curl_response "$response_status" "Pipeline Templates Repo imported successfully" 201
......@@ -343,9 +346,36 @@ check_renovate_json() {
fi
}
SUBGROUP="product"
SUBSUBGROUP="packages"
# If -s flag is set, create apps/sandbox groups
if [ "$sandbox_mode" = true ]; then
SUBGROUP="apps"
SUBSUBGROUP="sandbox"
# Create the "Packages" (apps) Subgroup under "Big Bang"
response_body=$(gum spin --show-error --spinner dot --title "Creating Packages Subgroup under Big Bang.." -- bash -c "\
curl --silent --write-out \"HTTPSTATUS:%{http_code}\" --request POST --header \"PRIVATE-TOKEN: $ROOT_TOKEN\" \
--header \"Content-Type: application/json\" \
--data '{\"name\": \"Packages\", \"path\": \"apps\", \"visibility\": \"public\", \"parent_id\": $BIG_BANG_GROUP_ID}' \
\"$GITLAB_URL/api/v4/groups\"")
response_status=$(echo "$response_body" | grep -o 'HTTPSTATUS:[0-9]\{3\}' | cut -d':' -f2)
handle_curl_response "$response_status" "Packages subgroup created successfully under Big Bang" 201
# Get the ID of the "Packages" group
PACKAGES_GROUP_ID=$(curl --silent --header "PRIVATE-TOKEN: $ROOT_TOKEN" "$GITLAB_URL/api/v4/groups?search=Packages" | jq '.[0].id')
# Create the "Sandbox" Subgroup under "Packages"
response_body=$(gum spin --show-error --spinner dot --title "Creating Sandbox Subgroup under Packages.." -- bash -c "\
curl --silent --write-out \"HTTPSTATUS:%{http_code}\" --request POST --header \"PRIVATE-TOKEN: $ROOT_TOKEN\" \
--header \"Content-Type: application/json\" \
--data '{\"name\": \"Sandbox\", \"path\": \"sandbox\", \"visibility\": \"public\", \"parent_id\": $PACKAGES_GROUP_ID}' \
\"$GITLAB_URL/api/v4/groups\"")
response_status=$(echo "$response_body" | grep -o 'HTTPSTATUS:[0-9]\{3\}' | cut -d':' -f2)
handle_curl_response "$response_status" "Sandbox subgroup created successfully under Packages" 201
fi
import_projects() {
# Get the ID of the group
GROUP_ID=$(curl --silent --header "PRIVATE-TOKEN: $TOKEN" "https://repo1.dso.mil/api/v4/groups?search=packages" | jq '.[] | select(.full_path == "big-bang/product/packages") | .id')
GROUP_ID=$(curl --silent --header "PRIVATE-TOKEN: $TOKEN" "https://repo1.dso.mil/api/v4/groups?search=$SUBSUBGROUP" | jq ".[] | select(.full_path == \"big-bang/$SUBGROUP/$SUBSUBGROUP\") | .id")
# Get the list of projects
RESPONSE=$(curl -s --header "PRIVATE-TOKEN: $TOKEN" "https://repo1.dso.mil/api/v4/groups/$GROUP_ID/projects?per_page=100&page=1")
......@@ -367,11 +397,11 @@ import_projects() {
)
# Get the ID of the target group
TARGET_GROUP_ID=$(curl --silent --header "PRIVATE-TOKEN: $ROOT_TOKEN" "$GITLAB_URL/api/v4/groups?search=product" | jq '.[0].id')
TARGET_GROUP_ID=$(curl --silent --header "PRIVATE-TOKEN: $ROOT_TOKEN" "$GITLAB_URL/api/v4/groups?search=$SUBSUBGROUP" | jq '.[0].id')
# Import projects
echo "$PROJECTS_WITH_RENOVATE" | while read -r project_name; do
IMPORT_URL="https://repo1.dso.mil/big-bang/product/packages/$project_name.git"
IMPORT_URL="https://repo1.dso.mil/big-bang/$SUBGROUP/$SUBSUBGROUP/$project_name.git"
response_body=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" --request POST --header "PRIVATE-TOKEN: $ROOT_TOKEN" \
--header "Content-Type: application/json" \
--data "{\"name\": \"$project_name\", \"path\": \"$project_name\", \"namespace_id\": $TARGET_GROUP_ID, \"visibility\": \"public\", \"import_url\": \"$IMPORT_URL\"}" \
......@@ -383,7 +413,7 @@ import_projects() {
import_all_projects() {
# Get the ID of the group
GROUP_ID=$(curl --silent --header "PRIVATE-TOKEN: $TOKEN" "https://repo1.dso.mil/api/v4/groups?search=packages" | jq '.[] | select(.full_path == "big-bang/product/packages") | .id')
GROUP_ID=$(curl --silent --header "PRIVATE-TOKEN: $TOKEN" "https://repo1.dso.mil/api/v4/groups?search=$SUBSUBGROUP" | jq ".[] | select(.full_path == \"big-bang/$SUBGROUP/$SUBSUBGROUP\") | .id")
# Get the list of projects
RESPONSE=$(curl -s --header "PRIVATE-TOKEN: $TOKEN" "https://repo1.dso.mil/api/v4/groups/$GROUP_ID/projects?per_page=100&page=1")
......@@ -405,11 +435,11 @@ import_all_projects() {
)
# Get the ID of the target group
TARGET_GROUP_ID=$(curl --silent --header "PRIVATE-TOKEN: $ROOT_TOKEN" "$GITLAB_URL/api/v4/groups?search=product" | jq '.[0].id')
TARGET_GROUP_ID=$(curl --silent --header "PRIVATE-TOKEN: $ROOT_TOKEN" "$GITLAB_URL/api/v4/groups?search=$SUBSUBGROUP" | jq '.[0].id')
# Import projects
echo "$PROJECTS_WITH_RENOVATE" | while read -r project_name; do
IMPORT_URL="https://repo1.dso.mil/big-bang/product/packages/$project_name.git"
IMPORT_URL="https://repo1.dso.mil/big-bang/$SUBGROUP/$SUBSUBGROUP/$project_name.git"
response_body=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" --request POST --header "PRIVATE-TOKEN: $ROOT_TOKEN" \
--header "Content-Type: application/json" \
--data "{\"name\": \"$project_name\", \"path\": \"$project_name\", \"namespace_id\": $TARGET_GROUP_ID, \"visibility\": \"public\", \"import_url\": \"$IMPORT_URL\"}" \
......@@ -441,10 +471,10 @@ delete_all_renovate_branches() {
local RETRY_DELAY=5
# Get the ID of the group
GROUP_RESPONSE=$(curl --silent --header "PRIVATE-TOKEN: $ROOT_TOKEN" "$GITLAB_URL/api/v4/groups?search=packages")
GROUP_RESPONSE=$(curl --silent --header "PRIVATE-TOKEN: $ROOT_TOKEN" "$GITLAB_URL/api/v4/groups?search=$SUBSUBGROUP")
SANITIZED_GROUP_RESPONSE=$(sanitize_json "$GROUP_RESPONSE")
GROUP_ID=$(echo "$SANITIZED_GROUP_RESPONSE" | jq -r '.[] | select(.full_path == "big-bang/product/packages") | .id')
GROUP_ID=$(echo "$SANITIZED_GROUP_RESPONSE" | jq -r ".[] | select(.full_path == \"big-bang/$SUBGROUP/$SUBSUBGROUP\") | .id")
if [ -z "$GROUP_ID" ]; then
handle_error "Failed to get group ID"
return
......@@ -519,7 +549,7 @@ fi
unprotect_main_branch_in_all_projects() {
# GitLab URL and token
GITLAB_URL="https://gitlab.dev.bigbang.mil"
GROUP_PATH="big-bang/product/packages"
GROUP_PATH="big-bang/$SUBGROUP/$SUBSUBGROUP"
MAX_RETRIES=3
RETRY_DELAY=5
......@@ -573,7 +603,7 @@ export GIT_PAGER=cat
revert_main_to_previous_bb0() {
# GitLab URL and token
local GITLAB_URL="gitlab.dev.bigbang.mil"
local GROUP_PATH="big-bang/product/packages"
local GROUP_PATH="big-bang/$SUBGROUP/$SUBSUBGROUP"
local PRIVATE_TOKEN=$(echo "$ROOT_TOKEN" | xargs) # Trim any leading/trailing spaces
local TMP_DIR=$(mktemp -d)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment