From 23db49fb722802381e915a06775b8f6c05049f71 Mon Sep 17 00:00:00 2001 From: Amin Al Ali Al Darwish Date: Thu, 27 Jun 2024 14:06:43 +0300 Subject: [PATCH 1/2] Added Code-Server-Sidecar Template --- .../templates/code-server-sidecar/README.md | 179 ++++++++++++++++++ .../code-server-sidecar/bunnyshell.yaml | 67 +++++++ .../code-server-sidecar/template.yaml | 14 ++ 3 files changed, 260 insertions(+) create mode 100644 .bunnyshell/templates/code-server-sidecar/README.md create mode 100644 .bunnyshell/templates/code-server-sidecar/bunnyshell.yaml create mode 100644 .bunnyshell/templates/code-server-sidecar/template.yaml diff --git a/.bunnyshell/templates/code-server-sidecar/README.md b/.bunnyshell/templates/code-server-sidecar/README.md new file mode 100644 index 00000000..5f0a11fd --- /dev/null +++ b/.bunnyshell/templates/code-server-sidecar/README.md @@ -0,0 +1,179 @@ +### Documentation for Integrating VS Code as a Sidecar Container using Bunnyshell + +## Overview + +This documentation provides a step-by-step guide to integrate VS Code as a sidecar container for remote development using Bunnyshell. The provided `bunnyshell.yaml` template showcases how to achieve this setup effectively. + +## Pre-Requisites + +### Adjusting the Dockerfile + +To integrate VS Code and avoid permission issues when mounting volumes across containers, you need to adjust the UID and GID of the files in your Dockerfile as follows: + +1. **Add a user with UID 1000 and GID 1000:** + NOTE: You are not restricted to using UID 1000 or GID 1000. Make sure to update the sidecar PUID and GUID accordingly. + ```Dockerfile + RUN addgroup -g 1000 code-server-user && \ + adduser -D -u 1000 -G code-server-user code-server-user && \ + adduser code-server-user nginx + ``` + +2. **Modify the main command to ensure proper permissions:** +This can be achieved by either modifying the main command with a `RUN` command or by adding to the `ENTRYPOINT` script to ensure the `code-server-user` has the correct permissions over the necessary directories. + + ```Dockerfile + CMD ["sh", "-c", "chown -R code-server-user:code-server-user /usr/share/nginx/html && nginx -g 'daemon off;'"] + ``` + + +### Understanding the Need for UID and GID + +When mounting volumes across containers, permission issues can arise between the main and sidecar containers. Specifying the user PUID and group PGID ensures consistency and avoids these issues. Use the command `id your_user` to find your user and group IDs. + +## Template Variables Explained + +### Crucial Lines in the `bunnyshell.yaml` + +1. **Exposing the Port for the Sidecar Container:** + + ```yaml + dockerCompose: + ports: + - '80:80' + - '8443:8443' + ``` + +2. **Defining the Sidecar Container:** + + ```yaml + dockerCompose: + pod: + sidecar_containers: + - + from: code-server + name: sidecar-code-server + shared_paths: + - + path: {{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}} + target: + path: '{{template.vars.SOURCE_CODE_PATH}}' + container: '@parent' + initial_contents: '@target' + ``` + + - `shared_paths[0].path`: The default workspace opened in the IDE. + - `shared_paths[0].target.path`: The path where the source code is in the main pod. + +3. **Generating the Hostname for the Code Server Sidecar:** + + ```yaml + hosts: + - + hostname: '{{template.vars.CODE_SERVER_HOST}}' + path: / + servicePort: '8443' + ``` + +4. **Code-Server Environment Variables:** + + Refer to [Code-Server Environment Variables Documentation](https://docs.linuxserver.io/images/docker-code-server/#environment-variables-from-files-docker-secrets). + + ```yaml + dockerCompose: + environment: + DEFAULT_WORKSPACE: '{{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}}' + HASHED_PASSWORD: {{template.vars.HASHED_PASSWORD}} + PASSWORD: {{template.vars.PASSWORD}} + PGID: '{{template.vars.PGID}}' + PROXY_DOMAIN: {{template.vars.PROXY_DOMAIN}} + PUID: '{{template.vars.PUID}}' + SUDO_PASSWORD: {{template.vars.SUDO_PASSWORD}} + SUDO_PASSWORD_HASH: {{template.vars.SUDO_PASSWORD_HASH}} + TZ: {{ template.vars.TZ }} + ``` + + - `PUID=1000`: UserID. + - `PGID=1000`: GroupID. + - `TZ=Etc/UTC`: Specify a timezone. + - `PASSWORD=password`: Optional web GUI password. + - `HASHED_PASSWORD=`: Optional hashed web GUI password. + - `SUDO_PASSWORD=password`: Optional sudo password. + - `SUDO_PASSWORD_HASH=`: Optionally set sudo password via hash. + - `PROXY_DOMAIN=code-server.my.domain`: Optional proxy domain. + - `DEFAULT_WORKSPACE=/config/workspace`: Default workspace directory. + +## Example `bunnyshell.yaml` File + +Below is the full `bunnyshell.yaml` configuration template: + +```yaml +kind: Environment +name: code-server +type: primary +templateVariables: + CODE_SERVER_DEFAULT_WORKSPACE: /config/workspace + SOURCE_CODE_PATH: /usr/share/nginx/html + CODE_SERVER_HOST: code-server-{{env.base_domain}} + HASHED_PASSWORD: '' + PASSWORD: password + PGID: '1000' + PROXY_DOMAIN: '' + PUID: '1000' + SUDO_PASSWORD: password + SUDO_PASSWORD_HASH: '' + TZ: Etc/UTC +components: + - + kind: Application + name: sample-app + gitRepo: 'https://github.com/aminalali8/mini-web.git' + gitBranch: master + gitApplicationPath: / + dockerCompose: + build: + context: . + dockerfile: Dockerfile + ports: + - '80:80' + - '8443:8443' + pod: + sidecar_containers: + - + from: code-server + name: sidecar-code-server + shared_paths: + - + path: {{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}} + target: + path: '{{template.vars.SOURCE_CODE_PATH}}' + container: '@parent' + initial_contents: '@target' + hosts: + - + hostname: 'web-{{env.base_domain}}' + path: / + servicePort: 80 + - + hostname: '{{template.vars.CODE_SERVER_HOST}}' + path: / + servicePort: '8443' + - + kind: SidecarContainer + name: code-server + dockerCompose: + image: 'lscr.io/linuxserver/code-server:latest' + environment: + DEFAULT_WORKSPACE: '{{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}}' + HASHED_PASSWORD: {{template.vars.HASHED_PASSWORD}} + PASSWORD: {{template.vars.PASSWORD}} + PGID: '{{template.vars.PGID}}' + PROXY_DOMAIN: {{template.vars.PROXY_DOMAIN}} + PUID: '{{template.vars.PUID}}' + SUDO_PASSWORD: '{{template.vars.SUDO_PASSWORD}}' + SUDO_PASSWORD_HASH: '{{template.vars.SUDO_PASSWORD_HASH}}' + TZ: '{{template.vars.TZ}}' + ports: + - '8443:8443' +``` + +This template facilitates the integration of VS Code as a sidecar container for remote development, ensuring a seamless and efficient development workflow. Adjust the provided `bunnyshell.yaml` and Dockerfile snippets to suit your application's needs. For further customization, refer to the [Code-Server Environment Variables Documentation](https://docs.linuxserver.io/images/docker-code-server/#environment-variables-from-files-docker-secrets). \ No newline at end of file diff --git a/.bunnyshell/templates/code-server-sidecar/bunnyshell.yaml b/.bunnyshell/templates/code-server-sidecar/bunnyshell.yaml new file mode 100644 index 00000000..35ae5a30 --- /dev/null +++ b/.bunnyshell/templates/code-server-sidecar/bunnyshell.yaml @@ -0,0 +1,67 @@ +kind: Environment +name: code-server +type: primary +templateVariables: + CODE_SERVER_DEFAULT_WORKSPACE: /config/workspace + SOURCE_CODE_PATH: /usr/share/nginx/html + CODE_SERVER_HOST: code-server-{{env.base_domain}} + HASHED_PASSWORD: '' + PASSWORD: password + PGID: '1000' + PROXY_DOMAIN: '' + PUID: '1000' + SUDO_PASSWORD: password + SUDO_PASSWORD_HASH: '' + TZ: Etc/UTC +components: + - + kind: Application + name: sample-app + gitRepo: 'https://github.com/aminalali8/mini-web.git' + gitBranch: master + gitApplicationPath: / + dockerCompose: + build: + context: . + dockerfile: Dockerfile + ports: + - '80:80' + - '8443:8443' + pod: + sidecar_containers: + - + from: code-server + name: sidecar-code-server + shared_paths: + - + path: {{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}} + target: + path: '{{template.vars.SOURCE_CODE_PATH}}' + container: '@parent' + initial_contents: '@target' + hosts: + - + hostname: 'web-{{env.base_domain}}' + path: / + servicePort: 80 + - + hostname: '{{template.vars.CODE_SERVER_HOST}}' + path: / + servicePort: '8443' + - + kind: SidecarContainer + name: code-server + dockerCompose: + image: 'lscr.io/linuxserver/code-server:latest' + environment: + DEFAULT_WORKSPACE: '{{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}}' + HASHED_PASSWORD: {{template.vars.HASHED_PASSWORD}} + PASSWORD: {{template.vars.PASSWORD}} + PGID: '{{template.vars.PGID}}' + PROXY_DOMAIN: {{template.vars.PROXY_DOMAIN}} + PUID: '{{template.vars.PUID}}' + SUDO_PASSWORD: {{template.vars.SUDO_PASSWORD}} + SUDO_PASSWORD_HASH: {{template.vars.SUDO_PASSWORD_HASH}} + TZ: {{ template.vars.TZ }} + ports: + - '8443:8443' diff --git a/.bunnyshell/templates/code-server-sidecar/template.yaml b/.bunnyshell/templates/code-server-sidecar/template.yaml new file mode 100644 index 00000000..2a5191e3 --- /dev/null +++ b/.bunnyshell/templates/code-server-sidecar/template.yaml @@ -0,0 +1,14 @@ +name: VS Code Sidecar Integration +description: This template showcases how to integrate VS Code as a sidecar container for remote development using Bunnyshell. It includes a sample application with a backend service and demonstrates how to configure the environment to avoid permission issues when mounting volumes across containers. +tags: + - vscode + - remote-development + - sidecar +icons: [ 'vscode', 'docker' ] +stack: + packages: + - name: Code Server + version: 'latest' +discoverable: true +categories: + - web-ides From 2b032d007ab660ef866751e18c48d1401749e96c Mon Sep 17 00:00:00 2001 From: Amin Al Ali Al Darwish Date: Thu, 27 Jun 2024 15:08:21 +0300 Subject: [PATCH 2/2] fixed interpolation issues and adjusted ports --- .../templates/code-server-sidecar/README.md | 14 +++++------ .../code-server-sidecar/bunnyshell.yaml | 24 +++++++++---------- .../code-server-sidecar/template.yaml | 4 ++-- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/.bunnyshell/templates/code-server-sidecar/README.md b/.bunnyshell/templates/code-server-sidecar/README.md index 5f0a11fd..23fd89d1 100644 --- a/.bunnyshell/templates/code-server-sidecar/README.md +++ b/.bunnyshell/templates/code-server-sidecar/README.md @@ -54,9 +54,9 @@ When mounting volumes across containers, permission issues can arise between the name: sidecar-code-server shared_paths: - - path: {{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}} + path: /config/workspace target: - path: '{{template.vars.SOURCE_CODE_PATH}}' + path: /usr/share/nginx/html container: '@parent' initial_contents: '@target' ``` @@ -81,7 +81,7 @@ When mounting volumes across containers, permission issues can arise between the ```yaml dockerCompose: environment: - DEFAULT_WORKSPACE: '{{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}}' + DEFAULT_WORKSPACE: '/config/workspace' HASHED_PASSWORD: {{template.vars.HASHED_PASSWORD}} PASSWORD: {{template.vars.PASSWORD}} PGID: '{{template.vars.PGID}}' @@ -111,8 +111,6 @@ kind: Environment name: code-server type: primary templateVariables: - CODE_SERVER_DEFAULT_WORKSPACE: /config/workspace - SOURCE_CODE_PATH: /usr/share/nginx/html CODE_SERVER_HOST: code-server-{{env.base_domain}} HASHED_PASSWORD: '' PASSWORD: password @@ -143,9 +141,9 @@ components: name: sidecar-code-server shared_paths: - - path: {{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}} + path: /config/workspace target: - path: '{{template.vars.SOURCE_CODE_PATH}}' + path: /usr/share/nginx/html container: '@parent' initial_contents: '@target' hosts: @@ -163,7 +161,7 @@ components: dockerCompose: image: 'lscr.io/linuxserver/code-server:latest' environment: - DEFAULT_WORKSPACE: '{{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}}' + DEFAULT_WORKSPACE: '/config/workspace' HASHED_PASSWORD: {{template.vars.HASHED_PASSWORD}} PASSWORD: {{template.vars.PASSWORD}} PGID: '{{template.vars.PGID}}' diff --git a/.bunnyshell/templates/code-server-sidecar/bunnyshell.yaml b/.bunnyshell/templates/code-server-sidecar/bunnyshell.yaml index 35ae5a30..4d082b83 100644 --- a/.bunnyshell/templates/code-server-sidecar/bunnyshell.yaml +++ b/.bunnyshell/templates/code-server-sidecar/bunnyshell.yaml @@ -2,8 +2,6 @@ kind: Environment name: code-server type: primary templateVariables: - CODE_SERVER_DEFAULT_WORKSPACE: /config/workspace - SOURCE_CODE_PATH: /usr/share/nginx/html CODE_SERVER_HOST: code-server-{{env.base_domain}} HASHED_PASSWORD: '' PASSWORD: password @@ -34,9 +32,9 @@ components: name: sidecar-code-server shared_paths: - - path: {{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}} + path: /config/workspace target: - path: '{{template.vars.SOURCE_CODE_PATH}}' + path: /usr/share/nginx/html container: '@parent' initial_contents: '@target' hosts: @@ -47,21 +45,21 @@ components: - hostname: '{{template.vars.CODE_SERVER_HOST}}' path: / - servicePort: '8443' + servicePort: 8443 - kind: SidecarContainer name: code-server dockerCompose: - image: 'lscr.io/linuxserver/code-server:latest' + image: 'lscr.io/linuxserver/code-server:4.90.3' environment: - DEFAULT_WORKSPACE: '{{template.vars.CODE_SERVER_DEFAULT_WORKSPACE}}' - HASHED_PASSWORD: {{template.vars.HASHED_PASSWORD}} - PASSWORD: {{template.vars.PASSWORD}} + DEFAULT_WORKSPACE: /config/workspace + HASHED_PASSWORD: '{{template.vars.HASHED_PASSWORD}}' + PASSWORD: '{{template.vars.PASSWORD}}' PGID: '{{template.vars.PGID}}' - PROXY_DOMAIN: {{template.vars.PROXY_DOMAIN}} + PROXY_DOMAIN: '{{template.vars.PROXY_DOMAIN}}' PUID: '{{template.vars.PUID}}' - SUDO_PASSWORD: {{template.vars.SUDO_PASSWORD}} - SUDO_PASSWORD_HASH: {{template.vars.SUDO_PASSWORD_HASH}} - TZ: {{ template.vars.TZ }} + SUDO_PASSWORD: '{{template.vars.SUDO_PASSWORD}}' + SUDO_PASSWORD_HASH: '{{template.vars.SUDO_PASSWORD_HASH}}' + TZ: '{{ template.vars.TZ }}' ports: - '8443:8443' diff --git a/.bunnyshell/templates/code-server-sidecar/template.yaml b/.bunnyshell/templates/code-server-sidecar/template.yaml index 2a5191e3..c3edc43e 100644 --- a/.bunnyshell/templates/code-server-sidecar/template.yaml +++ b/.bunnyshell/templates/code-server-sidecar/template.yaml @@ -7,8 +7,8 @@ tags: icons: [ 'vscode', 'docker' ] stack: packages: - - name: Code Server - version: 'latest' + - name: Linuxserver CodeServer + version: '4.90.3' discoverable: true categories: - web-ides