Skip to content

Improve Development Experience #4486

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
97 changes: 97 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Cloud Controller Development Environment

This document outlines how to set up and use the development environment for the Cloud Controller.

## Getting Started

1. **Prerequisites**: Ensure you have Docker and Visual Studio Code with the "Remote - Containers" extension installed.
2. **Launch the Environment**:
* Open the `cloud_controller_ng` project folder in VS Code.
* When prompted, click **"Reopen in Container"**. This will build the Docker images and start the development container. Also you can use the command palette (`Ctrl+Shift+P` or `Cmd+Shift+P` on macOS) and select **"Dev Containers: Reopen in Container"** or go to the remote explorer and select **"Reopen in Container"**.
* The initial build may take some time as it installs all dependencies.

## Interacting with the Environment

Once the container is running, the startup script (`.devcontainer/scripts/codespaces_start.sh`) will automatically:

* Set up and seed the PostgreSQL and MariaDB databases.
* Configure the Cloud Controller application.
* Start all necessary services (UAA, Minio, Nginx, etc.).

## VS Code Launch Configurations

The `.vscode/launch.json` file contains several configurations for running and debugging different components of the Cloud Controller. You can access these from the "Run and Debug" panel in VS Code.

### Main Application

* **`[Postgres] CloudController`**: Runs the main Cloud Controller API using PostgreSQL as the database.
* **`[Mariadb] CloudController`**: Runs the main Cloud Controller API using MariaDB as the database.

> Note only one can be run at a time. Ensure the other is stopped before starting a new one.

### Workers & Scheduler

* **`[Postgres/Mariadb] CC Worker`**: Starts the generic background job worker against the respective database.
* **`[Postgres/Mariadb] CC Local Worker`**: Starts the local background job worker against the respective database.
* **`[Postgres/Mariadb] CC Scheduler`**: Starts the clock process for scheduling recurring tasks against the respective database.

> Note only one can be run at a time either against Postgres or Mysql. Ensure the other is stopped before starting a new one.

### Testing

* **`[Postgres/Mariadb] Unittests`**: Runs the complete RSpec test suite against the specified database.

### Cloud Foundry CLI

The environment comes pre-installed with the `cf8-cli` and `uaac`. You can interact with the local Cloud Foundry deployment from the VS Code terminal.

**API Endpoint**: `http://localhost:80`

**Admin Credentials**:

* **Username**: `ccadmin`
* **Password**: `secret`

**Example Login Workflow**:

1. **Target the API**:

```bash
cf api http://localhost:80 --skip-ssl-validation
```

2. **Log In**:

```bash
cf auth ccadmin secret
```

### PostgreSQL and MariaDB Access

You can connect directly to the databases running in the environment from the VS Code terminal.

#### PostgreSQL

* **Host**: `localhost`
* **Port**: `5432`
* **User**: `postgres`
* **Password**: `supersecret`

**Example Connection**:

```bash
PGPASSWORD=supersecret psql -h localhost -U postgres -d ccdb
```

#### MariaDB (MySQL)

* **Host**: `127.0.0.1`
* **Port**: `3306`
* **User**: `root`
* **Password**: `supersecret`

**Example Connection**:

```bash
mysql -h 127.0.0.1 -u root -psupersecret ccdb
```
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"nginx"
],
"workspaceFolder": "/workspace",
"initializeCommand": ".devcontainer/scripts/codespaces_init.sh",
"onCreateCommand": ".devcontainer/scripts/codespaces_start.sh",
"onCreateCommand": "bash .devcontainer/scripts/startup.sh",
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
Expand Down
3 changes: 1 addition & 2 deletions .devcontainer/docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3.3"
services:

# Dev Container
Expand All @@ -8,7 +7,6 @@ services:
context: ./
dockerfile: .devcontainer/images/devcontainer/Dockerfile
restart: unless-stopped
command: /bin/sh -c "while sleep 1000; do :; done"
volumes:
- .:/workspace:cached
- /var/run/docker.sock:/var/run/docker.sock
Expand All @@ -17,3 +15,4 @@ services:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
privileged: true
2 changes: 1 addition & 1 deletion .devcontainer/images/bbs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:1

RUN apt update && apt install -y jq && git clone --recurse-submodules -b $(curl -s https://api.github.com/repos/cloudfoundry/diego-release/releases/latest | jq -r '.tag_name') https://github.com/cloudfoundry/diego-release && cd ./diego-release/src/code.cloudfoundry.org && \
RUN apt update && git clone --recurse-submodules -b v2.118.0 https://github.com/cloudfoundry/diego-release && cd ./diego-release/src/code.cloudfoundry.org && \
CG_ENABLED=0 go install code.cloudfoundry.org/locket/cmd/locket && \
CG_ENABLED=0 go install code.cloudfoundry.org/bbs/cmd/bbs
VOLUME /bbs
Expand Down
132 changes: 127 additions & 5 deletions .devcontainer/images/devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,129 @@
FROM mcr.microsoft.com/vscode/devcontainers/ruby:3.2
FROM mcr.microsoft.com/devcontainers/base:ubuntu-24.04


SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Set environment variables for Ruby development
ENV BUNDLE_PATH=/home/vscode/.bundle
ENV GEM_HOME=/home/vscode/.gem
ENV GEM_PATH=/home/vscode/.gem
ENV RAILS_ENV=development
ENV RACK_ENV=development

# Install system dependencies for Ruby development
RUN wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | gpg --dearmor -o /usr/share/keyrings/cli.cloudfoundry.org.gpg && \
echo "deb [signed-by=/usr/share/keyrings/cli.cloudfoundry.org.gpg] https://packages.cloudfoundry.org/debian stable main" > /etc/apt/sources.list.d/cloudfoundry-cli.list && \
apt-get update && \
apt-get install -y \
# CF CLI
cf8-cli \
# Build tools
build-essential \
autoconf \
bison \
patch \
# Ruby dependencies
libssl-dev \
libreadline-dev \
zlib1g-dev \
libncurses5-dev \
libffi-dev \
libgdbm-dev \
libyaml-dev \
libsqlite3-dev \
sqlite3 \
libgmp-dev \
libgdbm6 \
libdb-dev \
uuid-dev \
# Database clients
postgresql-client \
postgresql-client-common \
mysql-client \
redis-tools \
# Database development headers
libpq-dev \
default-libmysqlclient-dev \
# Development tools
curl \
wget \
git \
vim \
nano \
htop \
tree \
jq \
unzip \
zip \
# Network tools
netcat-openbsd \
# XML/HTML processing
libxml2-dev \
libxslt1-dev \
# GPG for RVM
gnupg2 \
# Additional utilities
tmux \
screen \
less \
man-db \
&& rm -rf /var/lib/apt/lists/*

# Install yq v4 for the correct architecture
RUN YQ_ARCH=$(uname -m) && \
case $YQ_ARCH in \
x86_64) YQ_ARCH="amd64";; \
aarch64) YQ_ARCH="arm64";; \
esac && \
wget "https://github.com/mikefarah/yq/releases/download/v4.47.1/yq_linux_${YQ_ARCH}" -O /usr/local/bin/yq && \
chmod +x /usr/local/bin/yq


COPY --from=docker:dind /usr/local/bin/docker /usr/local/bin/
COPY .devcontainer/images/devcontainer/setup.sh /tmp/setup.sh
COPY .ruby-version /tmp/.ruby-version
USER vscode
RUN /tmp/setup.sh && sudo rm /tmp/setup.sh /tmp/.ruby-version

# Create necessary directories and set permissions
RUN mkdir -p $BUNDLE_PATH $GEM_HOME && chown -R vscode:vscode $BUNDLE_PATH $GEM_HOME

# Install GPG keys for RVM
RUN gpg2 --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

# Install RVM
RUN curl -sSL https://get.rvm.io | bash -s stable --path /home/vscode/.rvm

# Copy Ruby version file for reference
COPY .ruby-version /tmp/ruby-version

# Install Ruby using RVM with binary packages when available, fallback to parallel source compilation
RUN /bin/bash -l -c "source /home/vscode/.rvm/scripts/rvm && \
export rvm_make_opts=\"-j$(nproc)\" && \
export RUBY_CONFIGURE_OPTS=\"--disable-install-doc\" && \
rvm install $(cat /tmp/ruby-version) && \
rvm use $(cat /tmp/ruby-version) --default && \
gem install bundler"

# Configure Bundler and install cf-uaac as vscode user
RUN /bin/bash -l -c "source /home/vscode/.rvm/scripts/rvm && \
bundle config set --global path \"$BUNDLE_PATH\" && \
bundle config set --global jobs $(nproc) && \
bundle config set --global specific_platform true && \
gem install cf-uaac"

# Configure Git
RUN git config --global core.fileMode false

# Source RVM and configure shell
RUN echo 'export BUNDLE_PATH="$BUNDLE_PATH"' >> /home/vscode/.bashrc \
&& echo 'export GEM_HOME="$GEM_HOME"' >> /home/vscode/.bashrc \
&& echo 'export GEM_PATH="$GEM_PATH"' >> /home/vscode/.bashrc \
&& echo 'source /home/vscode/.rvm/scripts/rvm' >> /home/vscode/.bashrc

# Configure Git (useful defaults)
RUN git config --global init.defaultBranch main \
&& git config --global pull.rebase false \
&& git config --global core.autocrlf input

# Set working directory
WORKDIR /workspace
USER root
# Sleep forever to keep the container running
CMD ["tail", "-f", "/dev/null"]
59 changes: 0 additions & 59 deletions .devcontainer/images/devcontainer/setup.sh

This file was deleted.

17 changes: 0 additions & 17 deletions .devcontainer/scripts/codespaces_init.sh

This file was deleted.

12 changes: 0 additions & 12 deletions .devcontainer/scripts/codespaces_start.sh

This file was deleted.

10 changes: 0 additions & 10 deletions .devcontainer/scripts/setupIDEs.sh

This file was deleted.

Loading