Skip to content

Commit fb66cc7

Browse files
TheMrSheldonTim Hagen
and
Tim Hagen
authored
Configured DevContainer for Python Client; Fixed HF Unittest; Integrated Unittests into VSCode; Quality of Life (#660)
* Configured backend and python client tests for vscode and moved all devcontainer files to .devcontainer * removed old python-client/Dockerfile.dev and integrated into dev container * added launch target for vuetify tests * consolidated all tests into tests.yml * readded LICENSE file to python client * fixed minore issues in the application and added further documentation on frontend development * made linter happy and fixed backend workflow * fixed communicating HF Cache folder to hf * removed default_hf_home_in_tira_host --------- Co-authored-by: Tim Hagen <[email protected]>
1 parent 9dbe9eb commit fb66cc7

Some content is hidden

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

48 files changed

+450
-545
lines changed

Dockerfile.dev .devcontainer/Dockerfile.dev

+39-20
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,33 @@ RUN apt-get update && apt-get install -y sudo git locales
77
RUN echo "en_US.UTF-8 UTF-8" | tee -a /etc/locale.gen && locale-gen
88

99
########################################################################################################################
10-
# Create User #
10+
# Create Users #
1111
########################################################################################################################
12-
# Change root Password to 1234
13-
RUN echo 'root:1234' | chpasswd
14-
# Create new user: "dev" also with password 1234
15-
RUN useradd -ms /bin/bash dev && \
16-
echo 'dev:1234' | chpasswd && \
12+
RUN <<EOF
13+
# Create docker group for later
14+
addgroup docker
15+
16+
# Change root Password to 1234
17+
echo 'root:1234' | chpasswd
18+
19+
# Create new user: "dev" also with password 1234
20+
useradd -ms /bin/bash dev
21+
echo 'dev:1234' | chpasswd
1722
usermod -aG sudo dev
23+
usermod -aG docker dev
24+
EOF
1825

1926

2027
########################################################################################################################
2128
# Frontend #
2229
########################################################################################################################
2330
USER root
2431

25-
# https://stackoverflow.com/a/47680012
26-
RUN apt-get update && apt-get install -y curl gnupg2 && \
27-
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
28-
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
29-
30-
RUN apt-get update && apt-get install -y npm yarn
31-
32+
RUN <<EOF
33+
apt-get update
34+
apt-get install -y npm
35+
npm install --global yarn
36+
EOF
3237

3338

3439

@@ -38,20 +43,34 @@ RUN apt-get update && apt-get install -y npm yarn
3843
########################################################################################################################
3944
ENV PIP_BREAK_SYSTEM_PACKAGES 1
4045
USER root
41-
RUN <<EOF
42-
apt-get update && apt-get install -y python3 python3-pip python3-dev pkg-config default-libmysqlclient-dev \
46+
RUN apt-get update && apt-get install -y python3 python3-pip python3-dev pkg-config default-libmysqlclient-dev \
4347
libpcre3-dev
44-
pip3 install black flake8 isort mypy
45-
EOF
46-
RUN <<EOF
4748
# Create a dummy secret
48-
mkdir -p "/etc/discourse/" && echo "I am so secret" > "/etc/discourse/client-api-key"
49+
COPY <<EOF /etc/discourse/client-api-key
50+
I am so secret
4951
EOF
5052

5153
########################################################################################################################
5254
# Client #
5355
########################################################################################################################
54-
# NOT YET
56+
USER root
57+
RUN <<EOF
58+
# Install Java (some dependencies like python are already installed by the application module)
59+
apt-get update
60+
apt-get install -y openjdk-11-jdk
61+
# Install Docker and set correct permissions to the docker.sock
62+
apt-get install -y curl
63+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
64+
chmod a+r /etc/apt/keyrings/docker.gpg
65+
echo \
66+
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
67+
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
68+
tee /etc/apt/sources.list.d/docker.list > /dev/null
69+
apt-get update -y
70+
apt-get install -y docker-ce-cli
71+
touch /var/run/docker.sock
72+
chown root:docker /var/run/docker.sock
73+
EOF
5574

5675

5776

.devcontainer/devcontainer.json

+20-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
77
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
88
"dockerComposeFile": [
9-
"../docker-compose.dev.yml",
9+
"./docker-compose.dev.yml",
1010
"docker-compose.yml"
1111
],
1212

@@ -50,7 +50,7 @@
5050
// "shutdownAction": "none",
5151

5252
// Uncomment the next line to run commands after the container is created.
53-
"postCreateCommand": "cd frontend; yarn; cd ../application/; pip install -e .[test,dev]; make setup; make import-mock-data",
53+
"postCreateCommand": "cd frontend; yarn; cd ../python-client; pip install -e .[test,dev]; cd ../application/; pip install -e .[test,dev]; make setup; make import-mock-data",
5454

5555
// Configure tool-specific properties.
5656
"customizations": {
@@ -60,6 +60,14 @@
6060
"json.format.keepLines": true,
6161
"livePreview.portNumber": 3080,
6262
"remote.autoForwardPorts": false,
63+
"files.exclude": {
64+
"**/__pycache__": true,
65+
"**/.mypy_cache": true,
66+
"**/.pytest_cache": true,
67+
"**/*.egg-info": true,
68+
"**/node_modules": true,
69+
"application/.data-dumps": true
70+
},
6371
"launch": {
6472
"version": "0.2.0",
6573
"configurations": [
@@ -86,14 +94,22 @@
8694
},
8795
{
8896
"name": "TIRA Backend Tests",
89-
"type": "python",
97+
"type": "debugpy",
9098
"request": "launch",
9199
"program": "${workspaceFolder:Backend}/src/manage.py",
92100
"cwd": "${workspaceFolder:Backend}/test",
93101
"args": [ "test", "--failfast", "--settings=settings_test" ],
94102
"django": true,
95103
"env": { "PYTHONPATH": ":../src:.", "DJANGO_SETTINGS_MODULE": "settings_test" },
96104
"justMyCode": false
105+
},
106+
{
107+
"name": "Frontend Tests",
108+
"type": "node",
109+
"request": "launch",
110+
"runtimeExecutable": "yarn",
111+
"args": [ "test" ],
112+
"cwd": "${workspaceFolder:Frontend}"
97113
}
98114
],
99115
"compounds": [
@@ -122,6 +138,7 @@
122138
"ms-python.flake8",
123139
"ms-python.mypy-type-checker",
124140
"42Crunch.vscode-openapi",
141+
"vuetifyjs.vuetify-vscode"
125142
]
126143
}
127144
},
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.8'
21
services:
32
devenv:
43
build:
@@ -16,21 +15,21 @@ services:
1615
image: ghcr.io/authelia/authelia
1716
restart: unless-stopped
1817
volumes:
19-
- ./.devfiles/authelia/configuration.dev.yml:/config/configuration.yml
20-
- ./.devfiles/authelia/users-database.yml:/config/users_database.yml
18+
- ./devfiles/authelia/configuration.dev.yml:/config/configuration.yml
19+
- ./devfiles/authelia/users-database.yml:/config/users_database.yml
2120
nginx:
2221
image: lscr.io/linuxserver/nginx
2322
restart: unless-stopped
24-
ports:
25-
- "8080:8080"
26-
- "8081:8081"
27-
- "8082:8082"
23+
#ports:
24+
# - "8080:8080"
25+
# - "8081:8081"
26+
# - "8082:8082"
2827
external_links:
2928
- "auth:auth.tira.local"
3029
- "devenv:www.tira.local"
3130
volumes:
32-
- ./.devfiles/nginx/tira.conf:/config/nginx/site-confs/tira.conf
33-
- ./.devfiles/nginx/tira-backend.conf:/config/nginx/site-confs/tira-backend.conf
34-
- ./.devfiles/nginx/auth.conf:/config/nginx/site-confs/auth.conf
35-
- ./.devfiles/nginx/snippets/:/config/nginx/snippets/
36-
- ./.devfiles/nginx/certs/:/etc/nginx/certs/
31+
- ./devfiles/nginx/tira.conf:/config/nginx/site-confs/tira.conf
32+
- ./devfiles/nginx/tira-backend.conf:/config/nginx/site-confs/tira-backend.conf
33+
- ./devfiles/nginx/auth.conf:/config/nginx/site-confs/auth.conf
34+
- ./devfiles/nginx/snippets/:/config/nginx/snippets/
35+
- ./devfiles/nginx/certs/:/etc/nginx/certs/

.devcontainer/docker-compose.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.8'
21
services:
32
# Update this to the name of the service you want to work with in your docker-compose.yml file
43
devenv:
@@ -13,7 +12,7 @@ services:
1312

1413
volumes:
1514
# Update this to wherever you want VS Code to mount the folder of your project
16-
- ..:/workspaces:cached
15+
- ..:/workspaces/tira:cached
1716

1817
# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
1918
# cap_add:

.github/workflows/run-all-tests.yml

-42
This file was deleted.

.github/workflows/test-python-client-on-many-python-versions.yml

-27
This file was deleted.

.github/workflows/test-python-client.yml

-20
This file was deleted.

.github/workflows/tests.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Unit Tests
2+
3+
on: [push]
4+
5+
jobs:
6+
backend-tests:
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 15
9+
strategy:
10+
matrix:
11+
python-version: ["3.9", "3.10"]
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Install TIRA Python Client from Repo
19+
working-directory: ${{github.workspace}}/python-client
20+
run: |
21+
# Install tira from the repository since the pip version may not be up-to-date enough.
22+
# The install musst be editable (-e) since importing from tira fails otherwise
23+
pip3 install -e .[dev,test]
24+
- name: Install dependencies
25+
working-directory: ${{github.workspace}}/application
26+
run: |
27+
# Create a dummy DISRAPTOR_API_KEY
28+
sudo bash -c 'mkdir -p "/etc/discourse/" && echo "I am so secret" > "/etc/discourse/client-api-key"'
29+
pip3 install -e .[dev,test]
30+
make setup
31+
- name: Run backend tests
32+
working-directory: ${{github.workspace}}/application/test
33+
run: pytest
34+
35+
frontend-tests:
36+
runs-on: ubuntu-latest
37+
timeout-minutes: 15
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: 20.x
44+
- name: Install dependencies
45+
working-directory: ${{github.workspace}}/frontend
46+
run: yarn --frozen-lockfile
47+
- name: Run frontend tests
48+
working-directory: ${{github.workspace}}/frontend
49+
run: yarn test
50+
51+
python-client-test:
52+
runs-on: ubuntu-latest
53+
timeout-minutes: 15
54+
strategy:
55+
matrix:
56+
python-version: ["3.8", "3.9", "3.10", "3.11"]
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@v4
60+
- name: Set up Python ${{ matrix.python-version }}
61+
uses: actions/setup-python@v4
62+
with:
63+
python-version: ${{ matrix.python-version }}
64+
- name: Set up Docker Buildx
65+
uses: docker/setup-buildx-action@v2
66+
- name: Install Dependencies
67+
working-directory: ${{github.workspace}}/python-client
68+
run: |
69+
sudo apt-get install -y openjdk-11-jdk
70+
pip3 install .[test,dev]
71+
- name: Running Tests
72+
working-directory: ${{github.workspace}}/python-client
73+
run: |
74+
echo running on branch ${GITHUB_REF##*/}
75+
pytest

0 commit comments

Comments
 (0)