Skip to content

Commit 13f50f9

Browse files
committed
pushing the tango container
1 parent 1ca7c12 commit 13f50f9

File tree

10 files changed

+1178
-0
lines changed

10 files changed

+1178
-0
lines changed

tango_container/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
files downloaded during build process will be put here
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Dockerfile.app
2+
# - Creates Conda env from tango.yaml
3+
# - Installs Poetry into that env (no separate venvs)
4+
# - Clones & installs:
5+
# hz-b/lat2db
6+
# hz-b/bact-device-models
7+
# hz-b/bact-twin-architecture
8+
# (each via `poetry install`)
9+
# - Clones hz-b/dt4acc (no install step shown, change if needed)
10+
11+
FROM condaforge/mambaforge:24.3.0-0
12+
13+
ARG CONDA_ENV=tangoenv
14+
ENV CONDA_ENV=${CONDA_ENV}
15+
16+
SHELL ["/bin/bash", "-c"]
17+
18+
# Copy your environment file into the image (make sure tango.yaml is in the same folder as this Dockerfile)
19+
COPY tango.yaml /tmp/tango.yaml
20+
21+
# Create the Conda environment
22+
RUN mamba env create -f /tmp/tango.yaml -n ${CONDA_ENV} && \
23+
echo "source /opt/conda/etc/profile.d/conda.sh && conda activate ${CONDA_ENV}" >> /etc/bash.bashrc
24+
25+
# System deps + Poetry in the Conda env
26+
# (git is needed for cloning; build-essentials are handy for projects with native builds)
27+
RUN apt-get update && \
28+
apt-get install -y --no-install-recommends git build-essential && \
29+
rm -rf /var/lib/apt/lists/* && \
30+
conda run -n ${CONDA_ENV} python -V && \
31+
conda run -n ${CONDA_ENV} pip install --no-cache-dir poetry && \
32+
# Make Poetry install into the active Conda env instead of its own venv
33+
conda run -n ${CONDA_ENV} poetry config virtualenvs.create false
34+
35+
WORKDIR /opt
36+
37+
38+
# Clone repos
39+
RUN git clone https://github.com/hz-b/lat2db.git && \
40+
git clone https://github.com/hz-b/bact-device-models.git && \
41+
git clone https://github.com/hz-b/bact-twin-architecture.git && \
42+
git clone --branch backup-before-filterrepo --single-branch https://github.com/hz-b/dt4acc.git
43+
44+
# Install Poetry projects INTO the Conda env
45+
RUN conda run -n ${CONDA_ENV} poetry -C /opt/lat2db install && \
46+
conda run -n ${CONDA_ENV} poetry -C /opt/bact-device-models install && \
47+
conda run -n ${CONDA_ENV} poetry -C /opt/bact-twin-architecture install
48+
49+
# Expose the env on PATH for interactive shells
50+
ENV PATH="/opt/conda/envs/${CONDA_ENV}/bin:${PATH}"
51+
52+
# Default command: keep container alive for interactive work
53+
CMD ["bash", "-lc", "echo 'Container ready. Run: conda activate ${CONDA_ENV}'; tail -f /dev/null"]
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# DT4CC Tango Container Setup and Usage Guide
2+
3+
This guide provides step-by-step instructions for running the DT4CC Tango containers with MySQL database and Tango DataBaseDS.
4+
5+
## Prerequisites
6+
7+
- Docker and Docker Compose installed on your system
8+
- Local MySQL/MariaDB service should be **stopped** to avoid port conflicts
9+
10+
## Quick Start
11+
12+
### 1. Stop Local Database Services
13+
14+
Before starting the containers, ensure your local MySQL or MariaDB service is stopped to avoid port conflicts:
15+
16+
**On macOS:**
17+
```bash
18+
# Stop MySQL if running via Homebrew
19+
brew services stop mysql
20+
21+
# Or stop MariaDB
22+
brew services stop mariadb
23+
```
24+
25+
**On Linux:**
26+
```bash
27+
# Stop MySQL
28+
sudo systemctl stop mysql
29+
# or
30+
sudo systemctl stop mariadb
31+
```
32+
33+
**On Windows:**
34+
- Stop MySQL/MariaDB service from Services management console
35+
36+
### 2. Start the Database and Tango DataBaseDS
37+
38+
Navigate to the `tango-mysql` directory and start the database services:
39+
40+
```bash
41+
cd tango-mysql
42+
docker compose up -d
43+
```
44+
45+
This will start:
46+
- MySQL 8.0 database on port 3306
47+
- Tango DataBaseDS on port 10000
48+
- Both services will be connected via the `tango-net` network
49+
50+
Wait for the services to be healthy (check with `docker compose ps`).
51+
52+
### 3. Build and Start the Application Container
53+
54+
Return to the main directory and build the application container:
55+
56+
```bash
57+
cd ..
58+
docker compose -f docker-compose.app.yml build
59+
docker compose -f docker-compose.app.yml up -d
60+
```
61+
62+
This will:
63+
- Build the application container with Conda environment `tangoenv1`
64+
- Install all required Python packages and dependencies
65+
- Clone and install the required repositories (lat2db, bact-device-models, bact-twin-architecture, dt4acc)
66+
67+
### 4. Start the Tango Server
68+
69+
Access the application container and start the Tango server:
70+
71+
```bash
72+
docker exec -it tango_app bash
73+
```
74+
75+
Inside the container, activate the Conda environment and start the server:
76+
77+
```bash
78+
conda activate tangoenv1
79+
cd /opt/dt4acc
80+
python scripts/dt4acc_enhanced_tango.py
81+
```
82+
83+
You should see server startup messages and confirmation that the Tango server is running.
84+
85+
## Testing the Setup
86+
87+
### Basic Device Testing
88+
89+
Open a **new terminal** and access the container again:
90+
91+
```bash
92+
docker exec -it tango_app bash
93+
conda activate tangoenv1
94+
```
95+
96+
Test basic device connectivity:
97+
98+
```python
99+
python
100+
```
101+
102+
In the Python shell:
103+
104+
```python
105+
from tango import DeviceProxy
106+
107+
# Test power converter device
108+
dev = DeviceProxy("SimpleTangoServer/test/power_converter_Q3P2T6R")
109+
dev.current_setpoint = 5.1
110+
111+
# You should see logs showing twiss and orbit calculations
112+
```
113+
114+
### Using Test Scripts
115+
116+
Navigate to the test examples directory:
117+
118+
```bash
119+
cd /opt/dt4acc/tests/example
120+
```
121+
122+
#### Available Test Scripts
123+
124+
1. **Check Device Status:**
125+
```bash
126+
python check_device_status.py SimpleTangoServer/test/magnet_VS3M2T8R
127+
```
128+
129+
2. **Show Device Values:**
130+
```bash
131+
python show_device_values.py SimpleTangoServer/test/power_converter_Q3P2T1R
132+
```
133+
134+
3. **List All Devices:**
135+
```bash
136+
python list_all_devices.py
137+
```
138+
139+
4. **List All Servers:**
140+
```bash
141+
python list_all_servers.py
142+
```
143+
144+
5. **Update Device Value:**
145+
```bash
146+
python update_device_value.py <device_name> <attribute> <value>
147+
```
148+
149+
6. **Check Mapped Properties:**
150+
```bash
151+
python check_mapped_properties.py <device_name>
152+
```
153+
154+
## Container Management
155+
156+
### View Running Containers
157+
```bash
158+
docker ps
159+
```
160+
161+
### View Container Logs
162+
```bash
163+
# Application container logs
164+
docker logs tango_app
165+
166+
# Database logs
167+
docker logs tango-mysql-mysql-1
168+
169+
# DataBaseDS logs
170+
docker logs tango-mysql-databaseds-1
171+
```
172+
173+
### Stop All Services
174+
```bash
175+
# Stop application container
176+
docker compose -f docker-compose.app.yml down
177+
178+
# Stop database services
179+
cd tango-mysql
180+
docker compose down
181+
```
182+
183+
### Restart Services
184+
```bash
185+
# Restart database services
186+
cd tango-mysql
187+
docker compose restart
188+
189+
# Restart application container
190+
cd ..
191+
docker compose -f docker-compose.app.yml restart
192+
```
193+
194+
## Troubleshooting
195+
196+
### Port Conflicts
197+
If you encounter port conflicts:
198+
- Ensure local MySQL/MariaDB is stopped
199+
- Check if ports 3306 or 10000 are already in use: `lsof -i :3306` or `lsof -i :10000`
200+
201+
202+
203+
### Tango Server Issues
204+
If the Tango server doesn't start:
205+
1. Check that DataBaseDS is running and healthy
206+
2. Verify the TANGO_HOST environment variable
207+
3. Check the server logs for specific error messages
208+
209+
## Environment Details
210+
211+
- **Conda Environment:** `tangoenv1`
212+
- **Database:** MySQL 8.0
213+
- **Tango DataBaseDS:**
214+
- **Application:** DT4CC with enhanced Tango integration
215+
216+
217+
## File Structure
218+
219+
```
220+
dt4cc-tango/
221+
├── docker-compose.yml # Full stack (DB + App)
222+
├── docker-compose.app.yml # App only (requires external DB)
223+
├── Dockerfile.app # Application container definition
224+
├── tango.yaml # Conda environment specification
225+
├── tango-mysql/
226+
│ ├── compose.yaml # Database services
227+
│ └── init/ # SQL initialization scripts
228+
└── README.md # This guide
229+
```
230+
231+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# docker-compose.app.yml
2+
# Use this together with tango_mysql/compose.yaml to run only the app container.
3+
# Assumes the DB service is named "mysql" on network "tango-net".
4+
5+
services:
6+
app:
7+
build:
8+
context: .
9+
dockerfile: Dockerfile.app
10+
args:
11+
CONDA_ENV: tangoenv1
12+
container_name: tango_app
13+
environment:
14+
CONDA_ENV: tangoenv1
15+
TANGO_HOST: databaseds:10000
16+
DB_HOST: mysql
17+
DB_NAME: tango
18+
DB_USER: tango
19+
DB_PASSWORD: ${DB_APP_PASSWORD:-Tango@1234!}
20+
networks:
21+
- tango-net
22+
volumes:
23+
- app_data:/workspace
24+
command: ["bash", "-lc", "tail -f /dev/null"]
25+
26+
networks:
27+
tango-net:
28+
external: true
29+
30+
volumes:
31+
app_data:
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# docker-compose.yml
2+
# Starts MariaDB and an app container built from Dockerfile.app.
3+
# MariaDB runs your init SQL scripts automatically.
4+
5+
services:
6+
db:
7+
image: mariadb:11
8+
container_name: tango_db
9+
environment:
10+
MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-rootpw}
11+
MARIADB_DATABASE: tango
12+
MARIADB_USER: tango
13+
MARIADB_PASSWORD: ${DB_APP_PASSWORD:-Tango@1234!}
14+
ports:
15+
- "3306:3306"
16+
volumes:
17+
# Place your SQL files in ./sql next to this compose file
18+
- db_data:/var/lib/mysql
19+
- ./sql/00-create-and-grant.sql:/docker-entrypoint-initdb.d/00-create-and-grant.sql:ro
20+
- ./sql/01-load-schema.sql:/docker-entrypoint-initdb.d/01-load-schema.sql:ro
21+
- ./sql/10-bootstrap-ds.sql:/docker-entrypoint-initdb.d/10-bootstrap-ds.sql:ro
22+
healthcheck:
23+
test: ["CMD-SHELL", "mysqladmin ping -h localhost -u root -p${DB_ROOT_PASSWORD:-rootpw} --silent"]
24+
interval: 5s
25+
timeout: 3s
26+
retries: 30
27+
28+
app:
29+
build:
30+
context: .
31+
dockerfile: Dockerfile.app
32+
args:
33+
CONDA_ENV: tangoenv1
34+
container_name: tango_app
35+
depends_on:
36+
db:
37+
condition: service_healthy
38+
environment:
39+
CONDA_ENV: tangoenv
40+
DB_HOST: db
41+
DB_NAME: tango
42+
DB_USER: tango
43+
DB_PASSWORD: ${DB_APP_PASSWORD:-Tango@1234!}
44+
volumes:
45+
- app_data:/opt
46+
command: ["bash", "-lc", "tail -f /dev/null"]
47+
48+
volumes:
49+
db_data:
50+
app_data:

0 commit comments

Comments
 (0)