Skip to content

Commit f58a44c

Browse files
Merge pull request #1180 from threefoldtech/development_update_frontend
Cleanup and upgrade for backend & frontend servers
2 parents 1ee5bfa + 37e37dc commit f58a44c

149 files changed

Lines changed: 9100 additions & 65245 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/production.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: production
33

44

55

6-
## DEPLOY TAG FOR WIZARD IS SET MANUAL IN THE HELM FILES -> TODO
76
on:
87
push:
98
tags:
@@ -13,26 +12,18 @@ jobs:
1312
runs-on: ubuntu-latest
1413
steps:
1514
- uses: actions/checkout@v2
16-
- name: Login to docker hub
17-
run: docker login --username ${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_TOKEN }}
15+
- name: Login to GitHub Container Registry
16+
uses: docker/login-action@v2
17+
with:
18+
registry: ghcr.io
19+
username: ${{ github.actor }}
20+
password: ${{ secrets.GITHUB_TOKEN }}
1821
- name: Set config
1922
run: mv frontend/public/config.prod.js frontend/public/config.js
2023
- name: Build the Docker image
21-
run: docker build . --file Dockerfile --tag jimber/3botlogin:production-${{ github.sha }}
24+
run: docker build . --file Dockerfile --tag ghcr.io/${{ github.repository_owner }}/threefold-connect:production-${{ github.sha }}
2225
- name: Push the Docker image
23-
run: docker push jimber/3botlogin:production-${{ github.sha }}
24-
# deploy:
25-
# needs: build
26-
# runs-on: whale-replacement
27-
# steps:
28-
# - name: Login to docker hub
29-
# run: docker login --username ${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_TOKEN }}
30-
# - name: kill old docker
31-
# run: docker rm -f 3botlogin || true
32-
# - name: Pull Image
33-
# run: docker pull jimber/3botlogin:production-${{ github.sha }}
34-
# - name: Run new docker
35-
# run: docker run -d -it --restart=unless-stopped --name 3botlogin -v /opt/3botlogin/db/pythonsqlite.db:/usr/share/nginx/backend/pythonsqlite.db -v /opt/3botlogin/config.ini:/usr/share/nginx/backend/config.ini --network=3proxynet jimber/3botlogin:production-${{ github.sha }}
26+
run: docker push ghcr.io/${{ github.repository_owner }}/threefold-connect:production-${{ github.sha }}
3627

3728
deploy:
3829
needs: [build]
@@ -52,4 +43,4 @@ jobs:
5243
- name: Upgrade production on cluster
5344
run: |
5445
echo production-${{ github.sha }}
55-
helm upgrade threebotlogin helm_files -f helm_files/valuesProduction.yaml --set images.login.tag=production-${{ github.sha }} -n jimber
46+
helm upgrade threebotlogin helm_files -f helm_files/valuesProduction.yaml --set images.login.tag=production-${{ github.sha }} --set images.login.repo=ghcr.io/${{ github.repository_owner }}/threefold-connect -n jimber

.github/workflows/staging.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v2
12-
- name: Log into Docker Hub
12+
- name: Login to GitHub Container Registry
1313
uses: docker/login-action@v2
1414
with:
15-
username: ${{ secrets.TFDOCKERHUB_USERNAME }}
16-
password: ${{ secrets.TFDOCKERHUB_PASSWORD }}
15+
registry: ghcr.io
16+
username: ${{ github.actor }}
17+
password: ${{ secrets.GITHUB_TOKEN }}
1718

1819
- name: Set config
1920
run: mv frontend/public/config.staging.js frontend/public/config.js
2021
- name: Build the 3botlogin Docker image
21-
run: docker build . --file Dockerfile --tag threefolddev/3botlogin:staging-${{ github.sha }}
22+
run: docker build . --file Dockerfile --tag ghcr.io/${{ github.repository_owner }}/threefold-connect:staging-${{ github.sha }}
2223
- name: Push the 3botlogin Docker image
23-
run: docker push threefolddev/3botlogin:staging-${{ github.sha }}
24-
- name: Build wizard Docker image
25-
run: docker build wizard/ --file wizard/Dockerfile --tag threefolddev/wizard:staging-${{ github.sha }}
26-
- name: Push wizard Docker image
27-
run: docker push threefolddev/wizard:staging-${{ github.sha }}
24+
run: docker push ghcr.io/${{ github.repository_owner }}/threefold-connect:staging-${{ github.sha }}
2825

2926
deploy:
3027
needs: [build]
@@ -37,4 +34,4 @@ jobs:
3734
echo ${{ secrets.TF_KUBE_CONFIG }} | base64 --decode > ${HOME}/.kube/config
3835
- name: Install or Upgrade production on cluster
3936
run: |
40-
helm upgrade threebotlogin --install helm_files -f helm_files/valuesStaging.yaml --set images.login.tag=staging-${{ github.sha }} --set images.wizard.tag=staging-${{ github.sha }} -n threefoldconnect-staging
37+
helm upgrade threebotlogin --install helm_files -f helm_files/valuesStaging.yaml --set images.login.tag=staging-${{ github.sha }} --set images.login.repo=ghcr.io/${{ github.repository_owner }}/threefold-connect -n threefoldconnect-staging

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ frontend/dist
275275
# local env files
276276
frontend/.env.local
277277
frontend/.env.*.local
278+
frontend/.env
278279

279280
# Log files
280281
frontend/npm-debug.log*

Dockerfile

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,77 @@
1-
FROM node:16 AS builder
1+
FROM node:22 AS frontend-builder
22

33
COPY frontend /frontend
44
WORKDIR /frontend
55
RUN yarn install --frozen-lockfile && yarn build
66

7-
# COPY example /example
8-
# WORKDIR /example
9-
# RUN yarn install --frozen-lockfile && yarn build
10-
11-
COPY wizard /wizard
12-
WORKDIR /wizard
13-
RUN yarn install --frozen-lockfile && yarn build
147

8+
FROM python:3.11-alpine AS backend-builder
159

16-
FROM nginx:1.25
17-
COPY backend/requirements.txt requirements.txt
10+
ENV PYTHONUNBUFFERED=1 \
11+
PYTHONDONTWRITEBYTECODE=1 \
12+
PIP_NO_CACHE_DIR=1 \
13+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
14+
POETRY_VERSION=1.8.3 \
15+
POETRY_HOME="/opt/poetry" \
16+
POETRY_NO_INTERACTION=1 \
17+
POETRY_VIRTUALENVS_IN_PROJECT=true \
18+
POETRY_VIRTUALENVS_CREATE=true
1819

19-
RUN apt-get update && apt-get install -y \
20-
python3 \
21-
python3-pip \
20+
RUN apk add --no-cache \
2221
gcc \
23-
libssl-dev \
24-
python3-dev \
22+
musl-dev \
2523
libffi-dev \
26-
&& rm -rf /var/lib/apt/lists/*
27-
RUN pip3 install --break-system-packages uwsgi==2.0.26
28-
RUN pip3 install --break-system-packages --upgrade pip
29-
# Install stellar-sdk first to get compatible yarl version
30-
RUN pip3 install --break-system-packages stellar-sdk==9.1.0
31-
# Increase timeout and retries for slow network connections
32-
RUN pip3 install --break-system-packages \
33-
--default-timeout=100 \
34-
--retries=5 \
35-
-r requirements.txt --ignore-installed
36-
37-
COPY --from=builder /frontend/dist /var/www/html/frontend
38-
# COPY --from=builder /example/dist /var/www/html/example
39-
COPY --from=builder /wizard/dist /var/www/html/wizard
40-
41-
COPY backend/ /usr/share/nginx/backend
24+
openssl-dev \
25+
python3-dev \
26+
linux-headers \
27+
curl \
28+
make
29+
30+
RUN curl -sSL https://install.python-poetry.org | python3 -
31+
32+
ENV PATH="$POETRY_HOME/bin:$PATH"
33+
34+
WORKDIR /app
35+
COPY backend/pyproject.toml backend/poetry.lock* ./
36+
37+
RUN poetry install --only main --no-root --no-directory
38+
39+
COPY backend/ ./
40+
41+
RUN poetry install --only main
42+
43+
44+
FROM nginx:1.27-alpine AS runtime
45+
46+
RUN apk add --no-cache \
47+
libffi \
48+
openssl \
49+
libgcc \
50+
libstdc++ \
51+
sqlite-libs
52+
53+
ENV PYTHONUNBUFFERED=1 \
54+
PYTHONDONTWRITEBYTECODE=1 \
55+
VIRTUAL_ENV=/app/.venv \
56+
PATH="/usr/local/bin:/app/.venv/bin:$PATH" \
57+
LD_LIBRARY_PATH="/usr/local/lib"
58+
59+
COPY --from=backend-builder /usr/local/bin/python3.11 /usr/local/bin/python3.11
60+
COPY --from=backend-builder /usr/local/bin/python3 /usr/local/bin/python3
61+
COPY --from=backend-builder /usr/local/lib/python3.11 /usr/local/lib/python3.11
62+
COPY --from=backend-builder /usr/local/lib/libpython3.11.so.1.0 /usr/local/lib/libpython3.11.so.1.0
63+
COPY --from=backend-builder /usr/local/lib/libpython3.so /usr/local/lib/libpython3.so
64+
65+
COPY --from=backend-builder /app/.venv /app/.venv
66+
COPY --from=backend-builder /app /usr/share/nginx/backend
67+
COPY --from=frontend-builder /frontend/dist /var/www/html/frontend
4268

4369
COPY nginx.conf /etc/nginx/conf.d/default.conf
4470
COPY services.sh /services.sh
4571
RUN chmod +x /services.sh
72+
4673
WORKDIR /usr/share/nginx/backend/
4774

75+
EXPOSE 5000
76+
4877
CMD ["/services.sh"]

backend/README.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
1-
# 3botlogin_backend
1+
# ThreeFold Connect Backend
22

3-
The (temporary) backend for 3Bot login.
3+
Modern Python backend for ThreeFold Connect authentication and digital twin management.
44

5-
## Run service
5+
## Quick Start
66

7-
Go inside virtual environment:
7+
### Prerequisites
88

9-
`source ./venv/bin/activate`
9+
- Python 3.11+
10+
- Poetry (for dependency management)
11+
- Docker (optional, for containerized deployment)
1012

11-
Start UWSGI backend:
13+
### Local Development
1214

1315
```bash
14-
uwsgi --http :5000 --gevent 1000 --http-websockets --master --wsgi-file __main__.py --callable app -s 0.0.0.0:3030
15-
: 1643024584:0;uwsgi --http :5000 --gevent 1000 --http-websockets --master --wsgi-file __main__.py --callable app -s 0.0.0.0:3030
16+
# Install dependencies
17+
poetry install
18+
19+
# Run the backend
20+
poetry run python __main__.py
21+
```
22+
23+
Or activate the virtual environment:
24+
25+
```bash
26+
poetry shell
27+
python __main__.py
28+
```
29+
30+
The backend will start on `http://localhost:5000`
31+
32+
### Docker Development
33+
34+
```bash
35+
# Build the image
36+
docker build -t threefold-connect .
37+
38+
# Run the container
39+
docker run -d -p 5000:5000 \
40+
-v $(pwd)/pythonsqlite.db:/usr/share/nginx/backend/pythonsqlite.db \
41+
-v $(pwd)/config.ini:/usr/share/nginx/backend/config.ini \
42+
threefold-connect
1643
```
1744

1845
## Data to save

backend/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
app.register_blueprint(api_crypt)
2424
app.register_blueprint(api_payment)
2525

26-
CORS(app, support_credentials=True, resources={r"*": {"origins": ["*"]}})
26+
CORS(app, supports_credentials=True, resources={r"*": {"origins": ["*"]}})
2727

2828
logging.getLogger("werkzeug").setLevel(level=logging.ERROR)
2929
logging.getLogger("socketio").setLevel(level=logging.ERROR)

backend/node_modules/.yarn-integrity

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)