Skip to content

Commit

Permalink
✨ Cloud Platform enhancements (#11)
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Woffenden <jacob.woffenden@digital.justice.gov.uk>
  • Loading branch information
Jacob Woffenden authored Feb 1, 2024
1 parent 48bdb68 commit 892f65a
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 2 deletions.
12 changes: 11 additions & 1 deletion features/src/cloud-platform/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- markdownlint-disable MD003 -->
<!-- markdownlint-disable MD003 MD024 -->
# Changelog

All notable changes to this project will be documented in this file.
Expand All @@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.2] - 2024-01-31

### Added

- Dependency on `ghcr.io/ministryofjustice/devcontainer-feature/kubernetes`

- Curated Kubernetes configuration file

- ZSH prompt extension

## [0.0.1] - 2024-01-30

### Added
Expand Down
17 changes: 16 additions & 1 deletion features/src/cloud-platform/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
{
"id": "cloud-platform",
"version": "0.0.1",
"version": "0.0.2",
"name": "Cloud Platform",
"description": "Installs the Cloud Platform CLI",
"options": {
"cloudPlatformCliVersion": {
"type": "string",
"description": "Version of the Cloud Platform CLI to install",
"default": "latest"
},
"installCloudPlatformKubeconfig": {
"type": "boolean",
"description": "Wether to install the Cloud Platform kubeconfig",
"default": true
},
"installCloudPlatformPrompt": {
"type": "boolean",
"description": "Wether to install the Cloud Platform prompt",
"default": true
}
},
"dependsOn": {
"ghcr.io/ministryofjustice/devcontainer-feature/kubernetes:0": {
"kubernetesCliVersion": "v1.26.13"
}
}
}
10 changes: 10 additions & 0 deletions features/src/cloud-platform/install-cloud-platform-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ get_system_architecture

GITHUB_REPOSITORY="ministryofjustice/cloud-platform-cli"
VERSION=${CLOUDPLATFORMCLIVERSION:-"latest"}
INSTALL_CLOUD_PLATFORM_KUBECONFIG=${INSTALLCLOUDPLATFORMKUBECONFIG:-"true"}
INSTALL_CLOUD_PLATFORM_PROMPT=${INSTALLCLOUDPLATFORMPROMPT:-"true"}

if [[ "${VERSION}" == "latest" ]]; then
get_github_latest_tag "${GITHUB_REPOSITORY}"
Expand All @@ -29,4 +31,12 @@ install --owner=vscode --group=vscode --mode=775 cloud-platform /usr/local/bin/c

install --owner=vscode --group=vscode --mode=775 completions/cloud-platform.zsh /usr/local/share/zsh/site-functions/_cloud-platform

if [[ "${INSTALL_CLOUD_PLATFORM_KUBECONFIG}" == "true" ]]; then
install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/home/vscode/.kube/config /home/vscode/.kube/config
fi

if [[ "${INSTALL_CLOUD_PLATFORM_PROMPT}" == "true" ]]; then
install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/home/vscode/.devcontainer/promptrc.d/cloud-platform.sh /home/vscode/.devcontainer/promptrc.d/cloud-platform.sh
fi

rm --recursive --force LICENSE README.md completions "cloud-platform-cli_${VERSION}_linux_${ARCHITECTURE}.tar.gz"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# shellcheck disable=SC2016

PROMPT+='`\
kubectlCurrentContext=$(kubectl config current-context 2>/dev/null); \
kubectlCurrentNamespace=$(kubectl config view --minify --output "jsonpath={..namespace}"); \
kubectlClientId=$(kubectl config view --output json | jq -r ".users[0].user[\"auth-provider\"].config[\"client-id\"]"); \
kubectlServerVersion=$(kubectl version --output json 2>/dev/null | jq -r .serverVersion.gitVersion | sed "s/v//"); \
&& if [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ "${kubectlClientId}" == "REPLACE_WITH_CLIENT_ID" ]]; then \
echo -n "[ cluster: %{$fg[yellow]%}${kubectlCurrentContext} (requires authentication)%{$reset_color%} ] "; \
elif [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ ! -z "${kubectlServerVersion}" ]]; then \
echo -n "[ cluster: %{$fg[green]%}${kubectlCurrentContext} (authenticated)%{$reset_color%} ] "; \
else
echo -n "[ cluster: %{$fg[red]%}${kubectlCurrentContext} (issue with authentication)%{$reset_color%} ] "; \
fi \
&& if [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ ! -z "${kubectlCurrentNamespace}" ]] && [[ "${kubectlCurrentNamespace}" == *"-prod"* ]]; then \
echo -n "[ namespace: %{$fg[red]%}${kubectlCurrentNamespace}%{$reset_color%} ] "; \
elif [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ ! -z "${kubectlCurrentNamespace}" ]]; then \
echo -n "[ namespace: %{$fg[green]%}${kubectlCurrentNamespace}%{$reset_color%} ] "; \
fi \
`'
37 changes: 37 additions & 0 deletions features/src/cloud-platform/src/home/vscode/.kube/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
apiVersion: v1
kind: Config
preferences:
colors: true

####################################################################################################
#
# Changes to this file will be overwritten when rebuilding the dev container.
#
####################################################################################################

current-context: cloud-platform-live

clusters:
- name: cloud-platform-live
cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeE1EWXlPREUyTXprMU5sb1hEVE14TURZeU5qRTJNemsxTmxvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTDNZCk9jcWxuVUdZTGR6TFlZTFcyOHVVWk1QdGE3TWJTK09EbTh4RWNXNlRVMXoyeFovcUNwSUhRS0VGelk2SWJwVSsKaHB0Z2VrRnNKQllEc2pjRjhRSTNPSkFaMFVjMXpNaXo1TFE2ZU1pOENsbmRMYnk4NWRNLzliRGZ0T1dlMDVqcQpYSENmYW9RNWR0Y3NCbWplWFAzbm1ZZGRJcTBiRUZZMTJiQjkvOTRLRVJSdnp4U3oxNkg5VkJwdzA3UVArTFRTCnRKT2JjWWlzcEFSTXJUVTlZa1pVS1lJT2FUYnBqRHhHVGdMNm1EaWNSdHlQeU9admx0MUFSTFR3NUpBVG42WUYKaXNCMkt5cHA2Q05DNDVoaFVpU05vZE9vaUcxNVRpNU5WeWM5azQ4eTFqZWExZ0kzTnM0VGFpQXRxNEhPTHR3NQpML2RqMEFRTTJIalZlVG90TVJVQ0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFHUCs2RTZCMDVNSmxFZ04zcEJkRUxEa29yakEKMGJ0SmR2S1lEakkyWTE0cGtSMFlacXZjT2Zkd0tOM1VuL2FYblllT21xNFExdHRpMUZQRDR6MTE0TFU4VjBTcwo3Q080azE5NzNMVGxValRGTVZNNHZoZXlXc0JLRzJxZW10TGhkVjJGSDh1Y2lDZnVWd0hNb3lQTmJJdktCSVFOCnFIS08wclU0bElpSzVrcEdydXBZYWRIV3pLL0VMTlk5alZtelJxcXpGQ3lmVjJuWGZJK2xrbXFUOGN5Y0FWbS8KOExSQjhnK1dhTGxLQThydWMzYmZIWUJNZ2J1ZkpzYTVaU3lGd2dkNlNua0dta1c2KzBERklRUVAweEl5ajRaWgpFL1JxL0QyNE5zK2ZNc3lxWVRUQ21rRktUdTJENzJvQllUdmt5bnQ3Rjh3a0gwSWRiK1MxMXNxUVdCcz0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
server: https://DF366E49809688A3B16EEC29707D8C09.gr7.eu-west-2.eks.amazonaws.com

users:
- name: auth0
user:
auth-provider:
name: oidc
config:
client-id: "REPLACE_WITH_CLIENT_ID"
client-secret: "REPLACE_WITH_CLIENT_SECRET"
id-token: "REPLACE_WITH_ID_TOKEN"
idp-issuer-url: https://justice-cloud-platform.eu.auth0.com/
refresh-token: "REPLACE_WITH_REFRESH_TOKEN"

contexts:
- name: cloud-platform-live
context:
cluster: cloud-platform-live
user: auth0
2 changes: 2 additions & 0 deletions features/test/cloud-platform/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ source dev-container-features-test-lib

check "cloud-platform version" cloud-platform version
check "cloud-platform completions existence" stat /usr/local/share/zsh/site-functions/_cloud-platform
check "cloud-platform kubeconfig existence" stat /home/vscode/.kube/config
check "cloud-platform prompt existence" stat /home/vscode/.devcontainer/promptrc.d/cloud-platform.sh

reportResults

0 comments on commit 892f65a

Please sign in to comment.