Skip to content

Commit a7fa904

Browse files
authored
Merge pull request #379 from costowell/develop
bump deps, add dev docker compose and Dockerfile, small fixes
2 parents b3159f8 + afd052c commit a7fa904

File tree

16 files changed

+1177
-2805
lines changed

16 files changed

+1177
-2805
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PACKET_IP=0.0.0.0
2+
PACKET_SERVER_NAME=localhost.localdomain:8000
3+
PACKET_DATABASE_URI=postgresql://postgres:mysecretpassword@postgres:5432/postgres
4+
PACKET_OIDC_CLIENT_SECRET=
5+
PACKET_LDAP_BIND_PASS=
6+
PACKET_LDAP_BIND_DN=

.github/workflows/node-js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
strategy:
1717
matrix:
18-
node-version: [10.x, 12.x, 14.x]
18+
node-version: [20.x]
1919

2020
steps:
2121
- uses: actions/checkout@v2

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10
1+
20

Dockerfile

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
1-
FROM docker.io/python:3.9-slim-buster
2-
MAINTAINER Devin Matte <[email protected]>
3-
4-
ENV DD_LOGS_INJECTION=true
1+
FROM docker.io/python:3.9-slim-trixie
52

3+
RUN ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
64
RUN apt-get -yq update && \
75
apt-get -yq --no-install-recommends install gcc curl libsasl2-dev libldap2-dev libssl-dev gnupg2 git && \
8-
apt-get -yq clean all
6+
apt-get -yq clean all \
7+
curl -sL https://deb.nodesource.com/setup_20.x | bash - && \
8+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor -o /usr/share/keyrings/yarn-archive-keyring.gpg && \
9+
echo "deb [signed-by=/usr/share/keyrings/yarn-archive-keyring.gpg] https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
10+
apt-get -yq update && \
11+
apt-get -yq --no-install-recommends install nodejs yarn
912

1013
RUN mkdir /opt/packet
11-
1214
WORKDIR /opt/packet
1315

1416
COPY requirements.txt /opt/packet/
15-
1617
RUN pip install -r requirements.txt
1718

18-
COPY . /opt/packet
19+
COPY package.json /opt/packet/
20+
COPY yarn.lock /opt/packet/
1921

20-
RUN curl -sL https://deb.nodesource.com/setup_10.x | grep -v 'sleep 20' | bash - && \
21-
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
22-
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
23-
apt-get -yq update && \
24-
apt-get -yq --no-install-recommends install nodejs yarn && \
25-
yarn install && \
26-
npm install -g gulp && \
27-
gulp production && \
22+
RUN yarn install && \
23+
yarn global add gulp
24+
25+
COPY . /opt/packet
26+
RUN gulp production && \
2827
rm -rf node_modules && \
2928
apt-get -yq remove nodejs npm yarn && \
3029
apt-get -yq autoremove && \
3130
apt-get -yq clean all
3231

33-
RUN ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
34-
3532
# Set version for apm
3633
RUN echo "export DD_VERSION=\"$(python3 packet/git.py)\"" >> /tmp/version
3734

Dockerfile.dev

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM docker.io/python:3.9-slim-trixie
2+
3+
RUN ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
4+
RUN apt-get -yq update && \
5+
apt-get -yq --no-install-recommends install gcc curl libsasl2-dev libldap2-dev libssl-dev gnupg2 git && \
6+
apt-get -yq clean all \
7+
curl -sL https://deb.nodesource.com/setup_20.x | bash - && \
8+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor -o /usr/share/keyrings/yarn-archive-keyring.gpg && \
9+
echo "deb [signed-by=/usr/share/keyrings/yarn-archive-keyring.gpg] https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
10+
apt-get -yq update && \
11+
apt-get -yq --no-install-recommends install nodejs yarn
12+
13+
RUN mkdir /opt/packet
14+
WORKDIR /opt/packet
15+
16+
COPY requirements.txt /opt/packet/
17+
RUN pip install -r requirements.txt
18+
19+
COPY package.json /opt/packet/
20+
COPY yarn.lock /opt/packet/
21+
22+
RUN yarn install && \
23+
yarn global add gulp
24+
25+
COPY . /opt/packet
26+
RUN gulp production && \
27+
rm -rf node_modules && \
28+
apt-get -yq remove nodejs npm yarn && \
29+
apt-get -yq autoremove && \
30+
apt-get -yq clean all
31+
32+
EXPOSE 8000
33+
34+
CMD ["/bin/bash", "-c", "python3 wsgi.py"]

README.md

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,44 @@ Packet is used by CSH to facilitate the freshmen packet portion of our introduct
77
the second major iteration of packet on the web. The first version was
88
[Tal packet](https://github.com/TalCohen/CSHWebPacket).
99

10-
## Setup
10+
11+
## Develop with Docker (Recommended)
12+
13+
1. Copy the `.env.example` to `.env` and insert the required credentials
14+
2. Build the dev environment with `docker compose build`
15+
3. Start the dev environment with `docker compose up`
16+
4. Run the database migrations with `docker exec -it packet-packet-1 flask db upgrade`
17+
5. Go check out the app at http://localhost.localdomain:8000
18+
19+
> Useful Tip: use `docker compose up --watch` so that you don't need to rebuild the container every time you want to test a change
20+
21+
### Secrets and configuration
22+
23+
Packet pulls in environment variables via the `config.env.py` so consult that file for all environment variables that configure the application.
24+
Use the `.env.example` file as an example to get started with development by making a copy called `.env` and adding what you need.
25+
26+
**Required configuration values:**
27+
28+
* `PACKET_DATABASE_URI` - Must be set to a valid [SQLAlchemy DB URI](http://flask-sqlalchemy.pocoo.org/2.3/config/#connection-uri-format). The `.env.example` has the default value for the containerized PostgreSQL database defined in the `docker-compose.yml`
29+
* `PACKET_LDAP_BIND_DN` - Must point to a valid CSH account on LDAP. Use the form
30+
`uid={username},cn=users,cn=accounts,dc=csh,dc=rit,dc=edu`.
31+
* `PACKET_LDAP_BIND_PASS` - The password for that CSH account.
32+
* `PACKET_SECRET_KEY` - Use a sufficiently long random string here. The `flask create-secret` command can generate a good one
33+
for you.
34+
* `PACKET_OIDC_CLIENT_SECRET` - Required to use CSH auth. Contact a current maintainer of packet for the details.
35+
36+
To switch between OIDC realms you'll need to set the modify the following values:
37+
38+
* `PACKET_OIDC_CLIENT_SECRET` - Unique to each realm. Again, contact a current maintainer of packet for the details.
39+
* `PACKET_OIDC_ISSUER` - The OIDC issuer URL.
40+
* `PACKET_REALM` - Set to `"csh"` or `"intro"` depending on the realm you want.
41+
42+
By default `PACKET_OIDC_ISSUER` and `PACKET_REALM` are configured for the CSH members realm.
43+
44+
## Develop locally (Not Recommended)
45+
46+
### Setup
47+
1148
**Requires Python 3.9 or newer.**
1249

1350
To get the server working you'll just need the Python dependencies and some secrets. There will be some UI issues due
@@ -18,6 +55,7 @@ Alternatively, you can set up a Docker container using `Dockerfile`. This is wha
1855
reliable method.
1956

2057
### Python dependencies
58+
2159
Use `pip3 install -r requirements.txt` to install the required python dependencies. A
2260
[venv](https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments) is *highly*
2361
recommended. To add new dependencies, add them to `requirements.in` and run `pip-compile requirements.in` to update
@@ -29,6 +67,7 @@ pain. Try using [WSL](https://docs.microsoft.com/en-us/windows/wsl/about) or fin
2967
trustworthy source.
3068

3169
### Frontend dependencies
70+
3271
To build any of the frontend dependencies you're going to need [node](https://nodejs.org/),
3372
[npm](https://www.npmjs.com/get-npm), and [yarn](https://yarnpkg.com/).
3473

@@ -49,6 +88,7 @@ npm install -g gulp
4988
```
5089

5190
### Local Development
91+
5292
* PostgreSQL
5393
You'll need a postgres instance to use as a development DB.
5494
You can use an existing database, like the instance used for the dev branch, use a database on another server, or spin up a container using docker or podman.
@@ -62,32 +102,8 @@ Once the container is up, run the following to set up the database tables.
62102
flask db upgrade
63103
```
64104

65-
### Secrets and configuration
66-
Packet supports 2 primary configuration methods:
67-
1. Environment variables - See `config.env.py` for the expected names and default values.
68-
2. Pyfile config - Create a `config.py` file in the root directory of the project and set variables to override the
69-
values in `config.env.py`.
70-
71-
Both methods can be used at the same time, though Pyfile config will take priority over environment variables.
105+
### Usage
72106

73-
**Required configuration values:**
74-
* `SQLALCHEMY_DATABASE_URI` - Must be set to a valid [SQLAlchemy DB URI](http://flask-sqlalchemy.pocoo.org/2.3/config/#connection-uri-format).
75-
A dev database for the project is hosted by CSH. Contact a current maintainer of packet for the details.
76-
* `LDAP_BIND_DN` - Must point to a valid CSH account on LDAP. Use the form
77-
`uid={username},cn=users,cn=accounts,dc=csh,dc=rit,dc=edu`.
78-
* `LDAP_BIND_PASS` - The password for that CSH account.
79-
* `SECRET_KEY` - Use a sufficiently long random string here. The `flask create-secret` command can generate a good one
80-
for you.
81-
* `OIDC_CLIENT_SECRET` - Required to use CSH auth. Contact a current maintainer of packet for the details.
82-
83-
To switch between OIDC realms you'll need to set the modify the following values:
84-
* `OIDC_CLIENT_SECRET` - Unique to each realm. Again, contact a current maintainer of packet for the details.
85-
* `OIDC_ISSUER` - The OIDC issuer URL.
86-
* `REALM` - Set to `"csh"` or `"intro"` depending on the realm you want.
87-
88-
By default `OIDC_ISSUER` and `REALM` are configured for the CSH members realm.
89-
90-
## Usage
91107
To run packet using the flask dev server use this command:
92108
```bash
93109
python3 wsgi.py
@@ -99,7 +115,8 @@ Alternative you can run it through [gunicorn](https://gunicorn.org/) using this
99115
gunicorn -b :8000 packet:app --access-logfile -
100116
```
101117

102-
### CLI
118+
## CLI
119+
103120
Packet makes use of the Flask CLI for exposing functionality to devs and admins. This is primarily designed to be used
104121
locally with the target DB set via the server's config values.
105122

docker-compose.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
services:
2+
packet:
3+
build:
4+
context: .
5+
dockerfile: ./Dockerfile.dev
6+
env_file:
7+
- path: ".env"
8+
required: true
9+
ports:
10+
- "8000:8000"
11+
develop:
12+
watch:
13+
- action: sync+restart
14+
path: packet
15+
target: /opt/packet/packet
16+
- action: rebuild
17+
path: frontend
18+
target: /opt/packet/frontend
19+
20+
networks:
21+
- packet-network-dev
22+
depends_on:
23+
postgres:
24+
condition: service_healthy
25+
restart: true
26+
postgres:
27+
image: "postgres:17"
28+
networks:
29+
- packet-network-dev
30+
environment:
31+
POSTGRES_USER: "postgres"
32+
POSTGRES_DB: "postgres"
33+
POSTGRES_PASSWORD: "mysecretpassword"
34+
ports:
35+
- "5432:5432"
36+
healthcheck:
37+
test: ["CMD-SHELL", "pg_isready -U postgres -d postgres"]
38+
interval: 10s
39+
retries: 5
40+
start_period: 30s
41+
timeout: 10s
42+
43+
networks:
44+
packet-network-dev:

frontend/scss/packet.scss

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
$csh-pink: #b0197e;
1+
@use "partials/base";
22

3-
@import "partials/base";
4-
5-
@import "components/switches";
6-
@import "components/datatables";
7-
@import "components/buttons";
8-
@import "components/signatures";
9-
@import "components/badges";
10-
@import "components/code";
3+
@use "components/switches";
4+
@use "components/datatables";
5+
@use "components/buttons";
6+
@use "components/signatures";
7+
@use "components/badges";
8+
@use "components/code";

frontend/scss/partials/_base.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use "sass:meta";
12
body {
23
padding-top: 40px;
34
}
@@ -6,7 +7,7 @@ body {
67
margin-top: 40px;
78
}
89

9-
@import "global";
10+
@include meta.load-css("global");
1011

1112
.header {
1213
display: flex;

0 commit comments

Comments
 (0)