From f9594b78f92d0d5b5b1b550112936ac0096b8ca7 Mon Sep 17 00:00:00 2001 From: Steve McMaster Date: Sat, 5 Nov 2022 16:28:13 +0000 Subject: [PATCH] Add android and python --- .drone.yml | 14 +++-- android/README.md | 113 +++++++++++++++++++++++++++++++++++++ android/main.tf | 140 ++++++++++++++++++++++++++++++++++++++++++++++ python/README.md | 113 +++++++++++++++++++++++++++++++++++++ python/main.tf | 140 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 514 insertions(+), 6 deletions(-) create mode 100644 android/README.md create mode 100644 android/main.tf create mode 100644 python/README.md create mode 100644 python/main.tf diff --git a/.drone.yml b/.drone.yml index 5d9e1a8..437d574 100644 --- a/.drone.yml +++ b/.drone.yml @@ -2,17 +2,19 @@ kind: pipeline name: default type: docker +environment: + CODER_URL: http://coder.coder.svc.cluster.local + CODER_SESSION_TOKEN: + from_secret: CODER_SESSION_TOKEN + CODER_TEMPLATE_VERSION: $${DRONE_COMMIT_SHA} + CODER_VERSION: 0.11.0 + steps: - name: push templates image: alpine:3.16 - environment: - CODER_URL: http://coder.coder.svc.cluster.local - CODER_SESSION_TOKEN: - from_secret: CODER_SESSION_TOKEN - CODER_TEMPLATE_VERSION: $${DRONE_COMMIT_SHA} commands: - apk add git - - wget -O- https://github.com/coder/coder/releases/download/v0.11.0/coder_0.11.0_linux_amd64.tar.gz | tar -xzf - -C /usr/local/bin + - wget -O- https://github.com/coder/coder/releases/download/v$${CODER_VERSION}/coder_$${CODER_VERSION}_linux_amd64.tar.gz | tar -xzf - -C /usr/local/bin coder - | for template in * ; do [ -e "$template/main.tf" ] || continue diff --git a/android/README.md b/android/README.md new file mode 100644 index 0000000..6e8bbf6 --- /dev/null +++ b/android/README.md @@ -0,0 +1,113 @@ +--- +name: Develop in Kubernetes +description: Get started with Kubernetes development. +tags: [cloud, kubernetes] +--- + +# Getting started + +This template creates a pod running the `codercom/enterprise-base:ubuntu` image. + +## RBAC + +The Coder provisioner requires permission to administer pods to use this template. The template +creates workspaces in a single Kubernetes namespace, using the `workspaces_namespace` parameter set +while creating the template. + +Create a role as follows and bind it to the user or service account that runs the coder host. + +```yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: coder +rules: + - apiGroups: [""] + resources: ["pods"] + verbs: ["*"] +``` + +## Authentication + +This template can authenticate using in-cluster authentication, or using a kubeconfig local to the +Coder host. For additional authentication options, consult the [Kubernetes provider +documentation](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs). + +### kubeconfig on Coder host + +If the Coder host has a local `~/.kube/config`, you can use this to authenticate +with Coder. Make sure this is done with same user that's running the `coder` service. + +To use this authentication, set the parameter `use_kubeconfig` to true. + +### In-cluster authentication + +If the Coder host runs in a Pod on the same Kubernetes cluster as you are creating workspaces in, +you can use in-cluster authentication. + +To use this authentication, set the parameter `use_kubeconfig` to false. + +The Terraform provisioner will automatically use the service account associated with the pod to +authenticate to Kubernetes. Be sure to bind a [role with appropriate permission](#rbac) to the +service account. For example, assuming the Coder host runs in the same namespace as you intend +to create workspaces: + +```yaml +apiVersion: v1 +kind: ServiceAccount +metadata: + name: coder + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: coder +subjects: + - kind: ServiceAccount + name: coder +roleRef: + kind: Role + name: coder + apiGroup: rbac.authorization.k8s.io +``` + +Then start the Coder host with `serviceAccountName: coder` in the pod spec. + +## Namespace + +The target namespace in which the pod will be deployed is defined via the `coder_workspace` +variable. The namespace must exist prior to creating workspaces. + +## Persistence + +The `/home/coder` directory in this example is persisted via the attached PersistentVolumeClaim. +Any data saved outside of this directory will be wiped when the workspace stops. + +Since most binary installations and environment configurations live outside of +the `/home` directory, we suggest including these in the `startup_script` argument +of the `coder_agent` resource block, which will run each time the workspace starts up. + +For example, when installing the `aws` CLI, the install script will place the +`aws` binary in `/usr/local/bin/aws`. To ensure the `aws` CLI is persisted across +workspace starts/stops, include the following code in the `coder_agent` resource +block of your workspace template: + +```terraform +resource "coder_agent" "main" { + startup_script = <= 1 + error_message = "Value must be greater than or equal to 1." + } +} + +provider "kubernetes" { + # Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences + config_path = var.use_kubeconfig == true ? "~/.kube/config" : null +} + +data "coder_workspace" "me" {} + +resource "coder_agent" "main" { + os = "linux" + arch = "amd64" + startup_script = <= 1 + error_message = "Value must be greater than or equal to 1." + } +} + +provider "kubernetes" { + # Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences + config_path = var.use_kubeconfig == true ? "~/.kube/config" : null +} + +data "coder_workspace" "me" {} + +resource "coder_agent" "main" { + os = "linux" + arch = "amd64" + startup_script = <