Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Role to deploy vscode #803

Merged
merged 3 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitguardian.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ secret:
name: userxxx
- match: passxxx
name: passxxx
- match: vscode123!
name: vscode-dummy
version: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# VSCode

This currated role can be used to install Visual Studio Code on the ace-box.
Two deployment options exist:
1. Direcly on the virtual machine.
2. On the Kubernetes cluster using Helm

See the section below for more info.

## Option 1 - Directly on the VM

This option is most suited when you need full access to the file system of the VM, and when you want to create a development environment where other dev tools will be installed.
The terminal in vscode will have direct access to the VM, so running commands like `java`, `dcoker`, ... will be possible.

> Note: this role still requires k3s for its ingress controller. This way it is also possible to combine this role with kubernetes-based workloads.

### Using the role

#### Role Requirements
This role depends on the following roles to be deployed beforehand:
```yaml
- include_role:
name: k3s
```

#### Deploying VSCode on the VM

``` yaml
- include_role:
name: vscode
vars:
vscode_flavour: "vm"
vscode_extensions:
- "vscjava.vscode-java-pack"
- "vmware.vscode-spring-boot"
- "redhat.vscode-xml"
- "ms-python.python"
- "{{ role_path }}/files/vscode/extensions/dynatrace.dynatrace-debugging-extension-0.7.0.vsix"
```

The `vscode_extensions` variable supports the installation of extensions. Check the [Open VSX Registry](https://open-vsx.org/) for a list of available extensions.

It is also possible to provide a vsix file to the role.

#### Deploying the dashboard

Installing the role also prepares the dashboard with links. Install the dashboard to visualise it.

``` yaml
- include_role:
name: dashboard
```

## Option 2 - On the Kubernetes cluster using Helm

This option deploys vscode on the kubernetes cluster directly, and requires k3s.
At this point, this would not give you many interaction possibilities with the VM directly.
It is therefor recommended to use the the option to directly deploy on the VM

### Using the role

#### Role Requirements
This role depends on the following roles to be deployed beforehand:
```yaml
- include_role:
name: k3s
```

#### Deploying VSCode on the Kubernetes Cluster

``` yaml
- include_role:
name: vscode
vars:
vscode_flavour: "kubernetes"
vscode_extensions:
- "vscjava.vscode-java-pack"
- "vmware.vscode-spring-boot"
- "redhat.vscode-xml"
- "ms-python.python"
- "/mnt/volume/extensions/dynatrace.dynatrace-debugging-extension-0.7.0.vsix"
```

The `vscode_extensions` variable supports the installation of extensions. Check the [Open VSX Registry](https://open-vsx.org/) for a list of available extensions.

It is also possible to provide a vsix file to the role.
To do that, place the `vsix` file in the `files/vscode/extensions` folder. This fodler will be mounted to the pod and you can then specify the `vsix` file in the `vscode_extensions` variable.

#### Deploying the dashboard

Installing the role also prepares the dashboard with links. Install the dashboard to visualise it.

``` yaml
- include_role:
name: dashboard
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
vscode_version: "4.96.4"
vscode_domain: "vscode.{{ ingress_domain }}"
vscode_namespace: "vscode"
vscode_password: ""
vscode_flavour: "kubernetes" # change to "vm" for a fully enabled dev environment
vscode_extensions:
- "vscjava.vscode-java-pack"
- "vmware.vscode-spring-boot"
- "redhat.vscode-xml"
- "ms-python.python"
- "dynatrace.dynatrace-apps"
- "/mnt/volume/extensions/dynatrace.dynatrace-debugging-extension-0.7.0.vsix" #only works for kubernetes deployment. check readme!
#- "{{ role_path }}/files/dynatrace.dynatrace-debugging-extension-0.7.0.vsix" #only works for vm deployments
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: Install Extension
become: true
ansible.builtin.shell: |
code-server --install-extension {{ code_extension }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
- include_role:
name: config-v2
tasks_from: set-var
vars:
var_key_to_set: "vscode_flavour"
var_value_to_set: "kubernetes"

# - include_tasks: create-secret.yml

- name: Generate extension installation block
become: true
become_user: root
lineinfile:
dest: "/tmp/vscode_extensions.txt"
line: "code-server --install-extension {{ item }}"
create: yes
state: present
mode: '0644' # Ensures the file is readable and writable by root
loop: "{{ vscode_extensions }}"

- name: Git checkout
ansible.builtin.git:
repo: 'https://github.com/coder/code-server.git'
dest: /tmp/checkout/vscode
version: "v{{ vscode_version }}"

- name: Template app-config.yml
template:
src: "{{ role_path }}/templates/vscode-values.yaml.j2"
dest: "{{ role_path }}/files/vscode-values.yaml"
owner: "{{ ace_box_user }}"
group: "{{ ace_box_user }}"
mode: "0644"

- name: Install VSCode
kubernetes.core.helm:
name: vscode
chart_ref: "/tmp/checkout/vscode/ci/helm-chart"
release_namespace: "{{ vscode_namespace }}"
create_namespace: true
wait: true
wait_timeout: 30m
values_files:
- "{{ role_path }}/files/vscode-values.yaml"
register: vscode_helm

- ansible.builtin.include_tasks: source-secret.yml

# Include Dashboard values
- set_fact:
include_dashboard_value_file: "{{ role_path }}/templates/vscode-dashboard.yml.j2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
- include_role:
name: config-v2
tasks_from: set-var
vars:
var_key_to_set: "vscode_flavour"
var_value_to_set: "vm"

- name: Download VSCode Deb
ansible.builtin.get_url:
url: "https://github.com/coder/code-server/releases/download/v{{vscode_version}}/code-server_{{vscode_version}}_amd64.deb"
dest: /tmp/code-server_{{vscode_version}}_amd64.deb

- name: Install VSCode
become: true
ansible.builtin.shell: |
sudo dpkg -i code-server_{{vscode_version}}_amd64.deb
sudo systemctl enable --now code-server@{{ace_box_user}}
args:
chdir: /tmp/

- name: Generate VSCode password
set_fact:
vscode_password: "{{ lookup('password', '/dev/null length=15 chars=ascii_letters') }}"

- name: Configure VSCode
ansible.builtin.template:
src: config.yaml.j2
dest: "/home/{{ ace_box_user }}/.config/code-server/config.yaml"
mode: 0600
vars:
private_ip: "{{ ansible_default_ipv4.address }}"

- include_role:
name: local-ingress
vars:
local_ingress_port: "8080"
local_ingress_domain: "{{ vscode_domain }}"
local_ingress_namespace: "{{ vscode_namespace }}"

- include_tasks: install-extension.yml
vars:
code_extension: "{{ item }}"
loop: "{{ vscode_extensions }}"

- name: Restart VSCode
become: true
ansible.builtin.shell: |
sudo systemctl restart code-server@{{ace_box_user}}

# - ansible.builtin.include_tasks: source-secret.yml

# Include Dashboard values
- set_fact:
include_dashboard_value_file: "{{ role_path }}/templates/vscode-dashboard.yml.j2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
- include_tasks: install-on-kubernetes.yml
when: vscode_flavour == "kubernetes"

- include_tasks: install-on-vm.yml
when: vscode_flavour == "vm"

- include_role:
name: dashboard
tasks_from: template-values-file
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
- name: Set facts - external endpoint
set_fact:
vscode_external_endpoint: "{{ ingress_protocol }}://{{ vscode_domain }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
- name: Source endpoints
kubernetes.core.k8s_info:
kind: Service
name: "vscode-code-server"
namespace: "{{ vscode_namespace }}"
register: vscode_http_data

- name: Set facts - internal endpoint
set_fact:
vscode_internal_endpoint: "http://{{ vscode_http_data.resources[0].spec.clusterIP }}:8080"
when: vscode_http_data is defined and vscode_http_data.resources[0] is defined
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 Dynatrace LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
- include_tasks: source-endpoints.yml
when: vscode_internal_endpoint is not defined

- name: Source VSCode secret
kubernetes.core.k8s_info:
kind: Secret
name: "vscode-code-server"
namespace: "{{ vscode_namespace }}"
register: vscode_secret_data

- name: Set secrets facts
set_fact:
vscode_password: "{{ vscode_secret_data.resources[0].data.password | b64decode }}"
when: vscode_secret_data is defined and vscode_secret_data.resources[0] is defined
Loading
Loading