Skip to content
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
64 changes: 64 additions & 0 deletions .github/workflows/container_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: build and tests

on:
push:
branches: ["main", "feature/containerize"]
pull_request:
branches: ["main"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build the Docker image
working-directory: deploy/container/chacra_image
run: docker build -t chacra .

- name: Set up Docker Compose
uses: docker/setup-compose-action@v1

- name: docker compose up -d
working-directory: deploy/container
run: |
docker compose up -d
sleep 30

- name: setup chacractl
run: |
pip install chacractl
cat > ~/.chacractl << 'EOF'
# This file was automatically generated by the chacractl CLI
# make sure to update it with the correct user and key to talk to the API
url = "http://127.0.0.1/"
user = "admin"
key = "secret"
ssl_verify = False
EOF

- name: view container log
run: docker logs --tail 1000 container-services-1

- name: test
run: |
wget https://chacra.ceph.com/r/libboost/master/9ea1fb8bdad548a88004db87761f173aa50dcc85/ubuntu/jammy/flavors/default/pool/main/b/boost1.87/ceph-libboost-atomic1.87-dev_1.87.0-1.1_amd64.deb

ls *.deb | chacractl binary create libboost/master/9ea1fb8bdad548a88004db87761f173aa50dcc85/ubuntu/jammy/amd64/flavors/default

rm -f ./ceph-libboost-atomic1.87-dev_1.87.0-1.1_amd64.deb

ls -l

wget http://127.0.0.1/binaries/libboost/master/9ea1fb8bdad548a88004db87761f173aa50dcc85/ubuntu/jammy/amd64/flavors/default/ceph-libboost-atomic1.87-dev_1.87.0-1.1_amd64.deb

ls -l

- name: tox run
run: docker exec container-services-1 bash -c "source /opt/chacra/bin/activate && cd /opt/chacra/src/chacra && tox run"

- name: clean
working-directory: deploy/container
run: |
rm -f ./ceph-libboost-atomic1.87-dev_1.87.0-1.1_amd64.deb
sudo docker compose down
5 changes: 5 additions & 0 deletions deploy/container/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin/**
repos/**
pgdata/**
logs/**
*.deb
66 changes: 66 additions & 0 deletions deploy/container/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## 1. what's this

Deploy chacra to a container.

This is essentially done by following an Ansible script, using Docker Compose to start RabbitMQ and PostgreSQL. Then, run chacra and Nginx inside the container.

It's in a pretty **raw** state right now, just enough to start and test chacra.


## 2. start

### 1. build chacra image
```shell
cd chacra_image/
sudo docker build -t chacra .
cd ..
```

### 2. start
```shell
sudo docker-compose up -d
sleep 30
```
please wait about 30s.


### 3. confiugre chacractl and test chacra

install chacractl first
```shell
pip install chacractl
```

set below txt to ~/.chacractl

```text
# This file was automatically generated by the chacractl CLI
# make sure to update it with the correct user and key to talk to the API

url = "http://127.0.0.1/"
user = "admin"
key = "secret"
ssl_verify = False
```


### 4. test

```shell
wget https://chacra.ceph.com/r/libboost/master/9ea1fb8bdad548a88004db87761f173aa50dcc85/ubuntu/jammy/flavors/default/pool/main/b/boost1.87/ceph-libboost-atomic1.87-dev_1.87.0-1.1_amd64.deb

ls *.deb | chacractl binary create libboost/master/9ea1fb8bdad548a88004db87761f173aa50dcc85/ubuntu/jammy/amd64/flavors/default

rm -f ./ceph-libboost-atomic1.87-dev_1.87.0-1.1_amd64.deb
# wget http://127.0.0.1/binaries/libboost/master/9ea1fb8bdad548a88004db87761f173aa50dcc85/ubuntu/jammy/amd64/flavors/default/ceph-libboost-atomic1.87-dev_1.87.0-1.1_amd64.deb
```


### 5. clean service
```shell
rm -f ./ceph-libboost-atomic1.87-dev_1.87.0-1.1_amd64.deb
sudo docker compose down
```

## 3. override conf without rebuild image
please see compose.yml:50 .
57 changes: 57 additions & 0 deletions deploy/container/chacra_image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM ubuntu:24.04

ARG APP_NAME="chacra"
# please do not pass env to container while start container.
# those env is valid on build image,not run time.
ENV APP_NAME=${APP_NAME}
ENV APP_HOME="/opt/${APP_NAME}"
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
python3 \
python3-pip \
virtualenv \
librabbitmq-dev \
libffi-dev \
pkg-config \
postgresql-client \
sudo \
git cmake libtool autoconf nginx reprepro createrepo-c\
&& mkdir -p /var/log/celery /etc/nginx/sites-available /etc/nginx/sites-enabled \
&& rm -f /etc/nginx/sites-enabled/default \
&& mkdir -p /var/lib/nginx/body /var/log/nginx \
&& useradd --system --no-create-home --shell /bin/false --user-group nginx \
&& chown -R nginx:nginx /var/lib/nginx /var/log/nginx \
&& chmod -R 755 /var/lib/nginx /var/log/nginx

RUN virtualenv ${APP_HOME} \
&& . ${APP_HOME}/bin/activate \
&& pip install --upgrade pip setuptools\
&& pip install -I -e git+https://github.com/ceph/chacra@main#egg=chacra \
&& pip install -r ${APP_HOME}/src/${APP_NAME}/requirements.txt \
&& pip install tox uv \
&& uv python install 3.11 3.12 3.13

COPY ./main.sh /bin/main.sh
COPY ./init-chacra-db.sh ${APP_HOME}/init-chacra-db.sh

COPY ./conf/prod.py ${APP_HOME}/src/${APP_NAME}/prod.py
COPY ./conf/prod_db.py ${APP_HOME}/src/${APP_NAME}/${APP_NAME}/prod_db.py
COPY ./conf/prod_api_creds.py ${APP_HOME}/src/${APP_NAME}/${APP_NAME}/prod_api_creds.py

# override origin conf.py to pass tox
COPY ./conf/conftest.py ${APP_HOME}/src/${APP_NAME}/${APP_NAME}/tests/conftest.py

COPY ./conf/alembic-prod.ini ${APP_HOME}/src/${APP_NAME}/alembic-prod.ini

COPY ./conf/nginx.conf /etc/nginx/nginx.conf
COPY ./conf/nginx_site.conf /etc/nginx/sites-available/${APP_NAME}.conf

RUN ln -s /etc/nginx/sites-available/${APP_NAME}.conf /etc/nginx/sites-enabled/${APP_NAME}.conf \
&& sed -i 's/2\.9\.9/2.9.10/g' ${APP_HOME}/src/${APP_NAME}/setup.py \
&& sed -i 's/2\.9\.9/2.9.10/g' ${APP_HOME}/src/${APP_NAME}/requirements.txt

ENV PECAN_CONFIG=${APP_HOME}/src/${APP_NAME}/prod.py


CMD ["/bin/sh","-c","/bin/main.sh"]
12 changes: 12 additions & 0 deletions deploy/container/chacra_image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## 1. APP_NAME

The default APP_NAME is chacra.

If you need to modify APP_NAME, please manually modify files including but not limited to nginx.conf,nginx_site.conf, etc. The reason one-click modification is not supported is that there are too many highly customized areas, and automatic modification would result in loss of universality. Therefore, if modification is needed, it can be implemented manually, which is actually not troublesome. Finally, pass this parameter when building.

Please note that passing this parameter when starting the container is ineffective.


## 2. how to start this container

This container cannot be started independently. You need to use docker compose to start postgresql and rabbitmq, and then the chacra container needs to be able to access the other two services via localhost.
68 changes: 68 additions & 0 deletions deploy/container/chacra_image/conf/alembic-prod.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts
script_location = /opt/chacra/src/chacra/alembic

# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# max length of characters to apply to the
# "slug" field
#truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; this defaults
# to alembic/versions. When using multiple version
# directories, initial revisions must be specified with --version-path
# version_locations = %(here)s/bar %(here)s/bat alembic/versions

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

sqlalchemy.url = postgresql://postgres:example@127.0.0.1/chacra


# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
Loading