Skip to content
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: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ devel/pg/postgresml/

devel/repo/cleanREMOTE
devel/repo/local

devel/setup/compose/repo
devel/mqttclient/

src/packages/*.rpm
Expand Down
2 changes: 2 additions & 0 deletions devel/setup/10-toolset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ if [ $rc == "0" ]; then

install-apt-toolset
fi

exit 0

24 changes: 0 additions & 24 deletions devel/setup/Dockerfile

This file was deleted.

27 changes: 27 additions & 0 deletions devel/setup/Dockerfile.rocky810
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM rockylinux/rockylinux:8.10
RUN touch /etc/hostname

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

USER root

ENV install="dnf install -y --allowerasing"
RUN $install dnf-plugins-core
RUN $install python3 python3-pip git wget curl pigz which zip sqlite
RUN $install openssh-server systemd sudo

RUN useradd build -U -m -d /home/build \
&& echo "build ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

USER build
WORKDIR /home/build/dev

RUN git clone https://github.com/pgedge/cli
# Temporary workaround for script behavior
RUN cd cli/devel/setup && bash -x ./10-toolset.sh || true
RUN cd cli/devel/setup && ./20-venv.sh
RUN cd cli/devel/setup && ./30-bashrc.sh
RUN source ~/.bashrc
RUN cd cli/devel/setup && ./40-awscli.sh

CMD /bin/bash
27 changes: 27 additions & 0 deletions devel/setup/Dockerfile.rocky95
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM rockylinux/rockylinux:9.5
RUN touch /etc/hostname

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

USER root

ENV install="dnf install -y --allowerasing"
RUN $install dnf-plugins-core
RUN $install python3 python3-pip git wget curl pigz which zip sqlite
RUN $install openssh-server systemd sudo

RUN useradd build -U -m -d /home/build \
&& echo "build ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

USER build
WORKDIR /home/build/dev

RUN git clone https://github.com/pgedge/cli
# Temporary workaround for script behavior
RUN cd cli/devel/setup && bash -x ./10-toolset.sh || true
RUN cd cli/devel/setup && ./20-venv.sh
RUN cd cli/devel/setup && ./30-bashrc.sh
RUN source ~/.bashrc
RUN cd cli/devel/setup && ./40-awscli.sh

CMD /bin/bash
40 changes: 40 additions & 0 deletions devel/setup/compose/Dockerfile.node.rocky95
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM rockylinux/rockylinux:9.5

RUN touch /etc/hostname
RUN dnf -y update && dnf remove -y subscription-manager dnf-plugin-subscription-manager

ENV install="dnf install -y --allowerasing"
RUN $install python3 python3-pip git wget curl pigz which zip sqlite postgresql
RUN $install openssh-server systemd sudo


RUN adduser --home-dir /home/pgedge --shell /bin/bash pgedge
RUN echo '%pgedge ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN rm -f /var/run/nologin
RUN sed -i 's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config
RUN sed -i 's/^PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
RUN ssh-keygen -A
RUN /usr/sbin/sshd

RUN mkdir -p /backups
RUN chown pgedge:pgedge /backups

USER pgedge
WORKDIR /home/pgedge
RUN mkdir -p .ssh/
RUN ssh-keygen -t rsa -b 4096 -N "" -f /home/pgedge/.ssh/id_rsa

RUN cat /home/pgedge/.ssh/id_rsa.pub >> /home/pgedge/.ssh/authorized_keys
RUN chmod 600 /home/pgedge/.ssh/authorized_keys
RUN chmod 700 /home/pgedge/.ssh/

RUN sudo chown pgedge:pgedge /home/pgedge/.ssh/id_rsa
RUN sudo chmod 600 /home/pgedge/.ssh/id_rsa

RUN sed -i '1iexport PGBACKREST_REPO1_CIPHER_PASS=Really_s3cure_password' ~/.bashrc

USER root
EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]

39 changes: 39 additions & 0 deletions devel/setup/compose/Dockerfile.node.ubuntu2204
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM ubuntu:22.04

ENV TZ=America/New_York
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get remove -y --purge snapd && apt-get -y upgrade

ENV install="apt-get install -y --no-install-recommends"
RUN $install python3 python3-pip git wget curl pigz zip sqlite3 postgresql
RUN $install openssh-server sudo systemd

RUN adduser --home /home/pgedge --shell /bin/bash pgedge
RUN echo '%pgedge ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN rm -f /var/run/nologin
RUN sed -i 's/^#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config
RUN sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
RUN ssh-keygen -A
RUN mkdir -p /run/sshd && /usr/sbin/sshd

RUN mkdir -p /backups
RUN chown pgedge:pgedge /backups

USER pgedge
WORKDIR /home/pgedge
RUN mkdir -p .ssh/
RUN ssh-keygen -t rsa -b 4096 -N "" -f /home/pgedge/.ssh/id_rsa

RUN cat /home/pgedge/.ssh/id_rsa.pub >> /home/pgedge/.ssh/authorized_keys
RUN chmod 600 /home/pgedge/.ssh/authorized_keys
RUN chmod 700 /home/pgedge/.ssh/

RUN sudo chown pgedge:pgedge /home/pgedge/.ssh/id_rsa
RUN sudo chmod 600 /home/pgedge/.ssh/id_rsa

RUN echo 'export PGBACKREST_REPO1_CIPHER_PASS=Really_s3cure_password' >> ~/.bashrc

USER root
EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]
25 changes: 25 additions & 0 deletions devel/setup/compose/Dockerfile.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM rockylinux/rockylinux:9-ubi
RUN touch /etc/hostname

# Set the working directory
WORKDIR /usr/src/

# Ensure /usr/src/repo is readable by the HTTP server
RUN mkdir -p /usr/src/repo
RUN chmod 755 /usr/src/repo

ADD proxy_server.py /usr/src/proxy_server.py

# Install required packages
RUN dnf update -y && dnf install -y \
python3-pip \
&& dnf clean all

# Install the HTTP server package
RUN pip3 install httpserver

# Expose the port the server will run on
EXPOSE 8000

# Command to run the HTTP server
CMD ["python3", "-m", "proxy_server", "--port", "8000", "--directory", "/usr/src/repo"]
38 changes: 38 additions & 0 deletions devel/setup/compose/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

.DEFAULT_GOAL := run

NUM_NODES ?= 2
OS_ARCH ?= linux/$(shell uname -m)
# Supports rocky95, ubuntu2204
OS_FLAVOR ?= rocky95
REPO ?= http://repo:8000/download

BUILD_OS_ARCH ?= linux/$(shell uname -m)
# Supports rocky95, rocky810
BUILD_OS_FLAVOR ?= rocky95

COMPOSE_ARGS := NUM_NODES=$(NUM_NODES) OS_ARCH=$(OS_ARCH) OS_FLAVOR=$(OS_FLAVOR) BUILD_OS_ARCH=$(BUILD_OS_ARCH) BUILD_OS_FLAVOR=$(BUILD_OS_FLAVOR) REPO=$(REPO)

.PHONY: compose-up
compose-up:
$(COMPOSE_ARGS) docker compose build && $(COMPOSE_ARGS) docker compose up -d

.PHONY: compose-down
compose-down:
docker compose down

.PHONY: exec-build
exec-build:
@docker exec -it pgedge-build-1 bash

define EXEC_NODE
.PHONY: exec-n$(1)
exec-n$(1):
@docker exec -u pgedge -it pgedge-node-$(1) bash
endef

.PHONY: node-ips
node-ips:
@docker compose ps -q node | xargs docker inspect -f '{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'

$(foreach n,1 2 3 4 5 6 7 8 9 10,$(eval $(call EXEC_NODE,$n)))
136 changes: 136 additions & 0 deletions devel/setup/compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Compose Setup for pgEdge Development

This setup allows you to build and run a multi-node pgEdge setup using Docker Compose. Below are the instructions and available arguments to customize your setup.

## Prerequisites

- Docker
- Docker Compose

## Files

- `docker-compose.yaml`: Defines the services and configurations for the Docker Compose setup.
- `Makefile`: Contains the commands to manage the Docker Compose setup.
- `proxy_server.py`: Contains the code which enables the repo proxy container
- `Dockerfile.node.<os>`: Dockerfiles for each supported operating system
- `Dockerfile.repo`: Dockerfile for the repo proxy server

## Usage

### Starting the Environment

To start the environment, run the following command:

```sh
make compose-up
```

This will build and start the services defined in the `docker-compose.yaml` file in Docker.

### Stopping the Environment

To stop the environment, run:

```sh
make compose-down
```

### Accessing the build container

The build container is where you make code changes and build packages.

To access the build container, run:

```sh
make exec-build
```

### Configuring the build container

The build container is setup the same as a standard development environment outside of Docker.

Required credentials (AWS, Git) are not configured on the build container.

You must configure these after starting the environment, and run `50-pull-IN.sh` if needed for your work.

### Understanding the repo container

The repo container serves as a local http server inside the network for fetching CLI packages.

It's setup as a proxy, where the default behavior is to serve a local package if it exists.

If a local package does not exist, it will fallback to a package available in the chosen REPO.

The chosen repo corresponds to the URL that you choose to configure:

- http://repo:8000/download corresponds with https://pgedge-download.s3.amazonaws.com/REPO
- http://repo:8000/upstream corresponds with https://pgedge-upstream.s3.amazonaws.com/REPO
- http://repo:8000/devel corresponds with https://pgedge-devel.s3.amazonaws.com/REPO

The `out` directory within the build container is mounted in the repo container to enable this setup.

You can monitor the behavior of the proxy via `docker logs pgedge-repo-1`

### Building the CLI packages

A common workflow in this setup is to leverage already built packages to increase development velocity.

If you are only working on the CLI code, you can typically just build that component:

```
source env.sh
./build.sh -X posix -c $bundle-cli -N $hubV
```

From there, utilize the node containers to test out your changes. Other packages will be pulled from the configured REPO.

### Accessing node containers

node containers are used to test changes you have developed within the build container.

You can access individual node containers using the following commands:

```sh
make exec-n1
make exec-n2
# ... up to make exec-n10
```

Once connected, you can setup the pgEdge CLI using the repo container:

```
wget $REPO/install.py
python3 install.py
cd pgedge
```

## Networking

All containers in the compose setup are attached to the same docker bridge network. This makes it easier to connect across nodes using hostnames.

- `repo` and `build` can be accessed directly by these hostnames since there are no replicas
- nodes can be accessed via hostnames prefixed with the compose name `pgedge-node-1`

## Available arguments

You can customize the setup using the following arguments:

- `NUM_NODES`: Number of node containers to deploy. Default is `2`.
- `OS_ARCH`: The OS architecture for the node containers. Default is `linux/$(uname -m)`.
- `OS_FLAVOR`: The OS flavor for the node containers. Supported values are `rocky95` and `ubuntu2204`. Default is `rocky95`.
- `BUILD_OS_FLAVOR`: The OS architecture for the build container. Default is `linux/$(uname -m)`.
- `BUILD_OS_ARCH`: The OS flavor for the build container. Supported values are `rocky95` and `rocky810`. Default is `rocky95`.
- `REPO`: The repository URL for downloading dependencies. Default is `http://repo:8000/download`.

### Example

To start the environment with 3 nodes and using `ubuntu2204` as the OS flavo, with the REPO set to upstream, run:

```sh
REPO=http://repo:8000/upstream NUM_NODES=3 OS_FLAVOR=ubuntu2204 make compose-up
```

## Notes

- Passwordless SSH is setup between the nodes to make it easier to test the cluster module
- The `PGBACKREST_REPO1_CIPHER_PASS` environment variable is set to `supersecret` by default. Change it as needed.
Loading