diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..c12f211 Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index ec1cc16..c3edb8f 100644 --- a/README.md +++ b/README.md @@ -1 +1,48 @@ -# delegate-quickstart-api \ No newline at end of file +# Deploy Docker Delegate and Setup Local K8s Infrastructure In Under 5 Minutes +## Prerquisites + +--- +- Tools Used + - [**k3d**](https://k3d.io/v5.4.6/) - K3d is wrapper to k3s on docker,we used k3d to create a single node Kubernetes cluster locally + - [**docker**](https://docs.docker.com/install/) to be able to use k3d + - [**kubectl**](https://k3d.io/v5.4.6/) to interact with the Kubernetes cluster + * You need to create a Harness API Key, using the Harness SaaS platform, the detailed steps for the same are mentioned [here](https://docs.harness.io/article/bn72tvbj6r-harness-rest-api-reference#step_1_create_a_harness_api_key_and_pat), further details on managing the API keys and the PAT can be found in our [documentation](https://docs.harness.io/article/tdoad7xrh9-add-and-manage-api-keys#harness_api_key). + * Next, start with [creating an organisation](https://docs.harness.io/article/36fw2u92i4-create-an-organization#step_1_create_a_harness_org), followed by [creating a project](https://docs.harness.io/article/36fw2u92i4-create-an-organization#step_3_create_a_project) and then start with creating a pipeline under any module of your choice, and move to the YAML view to find the "ORGIDENTIFIER" and "PROJECTIDENTIFIER". +![Alt Text](readme-images/YAML-view.png) + * For "ACCOUNTIDENTIFIER", is same as the Account ID, which could be found in the URL or under the account settings. +![Alt Text](readme-images/account-id.png) +:tada: Now get started with the script to get your delegate installed. + +## Steps to get the script running + +--- +* Export the below variables in your environment  + + - For Windows users: + + ```bash + set APIKEY=‘XXXXXX’ + set ACCOUNTIDENTIFIER=‘XXXXXX’ + set ORGIDENTIFIER=‘default’ + set PROJECTIDENTIFIER=‘TestProject’ + set TOKENIDENTIFIER=‘mytoken1’ + set KUBAENETESDELEGATENAME=‘k8delgate’ + set DOCKERDELEGATENAME=‘dockerdelegate’ + ``` + - For Linux and MacOS users: + + ```bash + export APIKEY='XXXXXX' + export ACCOUNTIDENTIFIER='XXXXXX' + export ORGIDENTIFIER='default' + export PROJECTIDENTIFIER='TestProject' + export TOKENIDENTIFIER='mytoken1' + export KUBAENETESDELEGATENAME='k8delgate' + export DOCKERDELEGATENAME='dockerdelegate' + ``` + +* Finally run the below  command + +```bash +curl -s -H "Accept:application/vnd.github.v3.raw" https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh>installk3d.sh && curl -s -H "Accept:application/vnd.github.v3.raw" https://raw.githubusercontent.com/ronakforgit/delegate-quickstart-api/delegate-script/automatedelegate.sh | bash +``` \ No newline at end of file diff --git a/automatedelegate.sh b/automatedelegate.sh new file mode 100644 index 0000000..cb71170 --- /dev/null +++ b/automatedelegate.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# +########################################################## +# Get Delegate docker-compose file and deploy it locally # +########################################################## +# +# +print_color(){ + GREEN=$(tput setaf 2) + NC=$(tput sgr0) + echo -e " " + echo -e "*${GREEN} ${1} ${NC} " + +} +# check if docker and kubectl are installed. + +if ! [ -x "$(command -v kubectl)" ]; then + print_color 'Error: kubectl is not installed.' >&2 + exit 1 +fi + +if ! [ -x "$(command -v docker)" ]; then + print_color 'Error: docker is not installed.' >&2 + exit 1 +fi + +#install k3ds +print_color " Installing k3ds.. " +bash installk3d.sh +print_color " Installing k3ds -- completed .. " + +#create single node cluster +print_color "Creating single node cluster.. " +k3d cluster create mylocalcluster +print_color " Creating single node cluster -- completed " + +#create delegate token +print_color " Creating delegate token and delegate.yml. " +curl -X POST "https://app.harness.io/gateway/ng/api/delegate-token-ng?accountIdentifier=${ACCOUNTIDENTIFIER}&orgIdentifier=${ORGIDENTIFIER}&projectIdentifier=${PROJECTIDENTIFIER}&tokenName=${TOKENIDENTIFIER}" -H "x-api-key: ${APIKEY}" -H "Content-Length: 0" --silent --show-error + +#download kubernetes delegate mainifest +curl -X POST "https://app.harness.io/gateway/ng/api/download-delegates/docker?accountIdentifier=${ACCOUNTIDENTIFIER}&orgIdentifier=${ORGIDENTIFIER}&projectIdentifier=${PROJECTIDENTIFIER}" -H "Content-Type: application/json" -H "x-api-key: ${APIKEY}" -o "docker-compose.yml" --silent --show-error --data-binary @- <