Skip to content

Commit

Permalink
chore: Update development work-flow (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
kesara authored Feb 17, 2025
1 parent 97ec597 commit a2fef96
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 58 deletions.
66 changes: 8 additions & 58 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,67 +30,17 @@ See [Code of Conduct](CODE_OF_CONDUCT.md).

## Setting up development environment

* Set up Python 3.8+ environment.
* Build docker image
```sh
docker build -f dev.Dockerfile -t author-tools:dev .
```
python3.8 -m venv venv
. venv/bin/activate
```

* Install required dependencies.
```
pip install -r requirements.txt
```

> **NOTE:** Known issue with Jinja conflict.
* Set up other dependencies for [xml2rfc](https://pypi.org/project/xml2rfc/).

* To use kramdown-rfc2629 and mmark, you need to have
[ruby](https://www.ruby-lang.org/) and [go](https://golang.org/) installed.

* Install npm dependencies
```
npm install
mv ./node_modules/.bin/idnits ./node_modules/.bin/idnits3
```

* Install [kramdown-rfc2629](https://github.com/cabo/kramdown-rfc2629).
```
bundle install
```

* Install [mmark](https://github.com/mmarkdown/mmark).
```
go get github.com/mmarkdown/mmark
```

* Create a tmp directory.
```
mkdir tmp
```

* Create a configuration file.
```
echo "UPLOAD_DIR = '$PWD/tmp'" > at/config.py
echo "VERSION = '9.9.9'" >> at/config.py
echo "REQUIRE_AUTH = False" >> at/config.py
echo "DT_LATEST_DRAFT_URL = 'https://datatracker.ietf.org/doc/rfcdiff-latest-json'" >> at/config.py
echo "ALLOWED_DOMAINS = ['ietf.org', 'ietf.org', 'rfc-editor.org']" >> at/config.py
PATH=$PATH:./node_modules/.bin/ python docker/version.py >> at/config.py
```

* Run flask server.
```
SITE_URL='http://localhost:5000' PATH=$PATH:./node_modules/.bin/ FLASK_APP=at FLASK_DEBUG=True flask run
```

## Running tests
* Install required dependencies for testing.
```
pip install -r requirements.dev.txt
* Run the docker image
```sh
docker run -it author-tools:dev
```

* Run unit tests.
```
PATH=$PATH:./node_modules/.bin/ python -m unittest discover tests
```sh
python3 -m unittest discover tests
```
144 changes: 144 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
FROM ubuntu:noble
LABEL maintainer="Kesara Rathnayake <[email protected]>"

ARG VERSION=6.6.6

ENV DEBIAN_FRONTEND=noninteractive
ENV PATH=$PATH:./node_modules/.bin
# Disable local file read for kramdown-rfc
ENV KRAMDOWN_SAFE=1

WORKDIR /usr/src/app

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Add nodejs 18.x
RUN apt-get update && \
apt-get install -y curl gpg && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list

RUN apt-get update && \
apt-get install -y \
software-properties-common \
gcc \
wget \
ruby \
python3 \
python3-venv \
libpango-1.0-0 \
libpango1.0-dev \
wdiff \
nodejs \
gawk \
bison \
flex \
make \
git \
build-essential \
cmake \
nginx \
supervisor && \
rm -rf /var/lib/apt/lists/* /var/log/dpkg.log && \
apt-get autoremove -y && \
apt-get clean -y

# Install rfcdiff
RUN wget https://github.com/ietf-tools/rfcdiff/archive/refs/tags/1.49.tar.gz && \
tar zxf 1.49.tar.gz -C /tmp/ && \
mv /tmp/rfcdiff-1.49/rfcdiff /bin && \
chmod +x /bin/rfcdiff && \
rm -rf 1.49.tar.gz /tmp/rfcdiff-1.49

# Install bap
RUN wget https://github.com/ietf-tools/bap/archive/refs/heads/master.zip && \
unzip -q master.zip -d /tmp/bap && \
cd /tmp/bap/bap-master/ && \
./configure && \
make && \
cp aex bap /bin && \
cd && \
rm -rf /tmp/bap master.zip

# Install idnits
RUN wget https://github.com/ietf-tools/idnits/archive/refs/tags/2.17.1.zip && \
unzip -q 2.17.1.zip -d ~/idnits && \
cp ~/idnits/idnits-2.17.1/idnits /bin && \
chmod +x /bin/idnits && \
rm -rf ~/idnits/idnits-2.17.1/idnits idnit 2.17.1.zip

# Install mmark
RUN arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) && \
wget "https://github.com/mmarkdown/mmark/releases/download/v2.2.46/mmark_2.2.46_linux_$arch.tgz" && \
tar zxf mmark_*.tgz -C /bin/ && \
rm mmark_*.tgz

# Build & install rst2rfcxml
RUN git clone --branch v1.5.0 --recurse-submodules https://github.com/dthaler/rst2rfcxml.git && \
cd rst2rfcxml && \
cmake -B build -DCMAKE_BUILD_TYPE=Release && \
cmake --build build && \
mv ./build/rst2rfcxml/rst2rfcxml /bin && \
chmod +x /bin/rst2rfcxml && \
cd .. && \
rm -rf rst2rfcxml

COPY Gemfile Gemfile.lock LICENSE README.md api.yml constraints.txt package-lock.json package.json requirements.txt docker/version.py ./
COPY at ./at

# Install JavaScript dependencies
RUN npm install

# Rename idnits v3 binary
RUN mv ./node_modules/.bin/idnits ./node_modules/.bin/idnits3

# Install Python dependencies
ENV PYTHONUNBUFFERED=1
ENV VENV_DIR=/usr/src/app/venv
RUN python3 -m venv $VENV_DIR
ENV PATH="$VENV_DIR/bin:$PATH"
RUN python -m pip install --upgrade pip
RUN python -m pip install -r requirements.txt -c constraints.txt

# Install Ruby dependencies
RUN gem install bundler && bundle install

# nginx unprivileged setup
RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log && \
sed -i '/user www-data;/d' /etc/nginx/nginx.conf && \
sed -i 's,/run/nginx.pid,/tmp/nginx.pid,' /etc/nginx/nginx.conf && \
sed -i "/^http {/a \ proxy_temp_path /tmp/proxy_temp;\n client_body_temp_path /tmp/client_temp;\n fastcgi_temp_path /tmp/fastcgi_temp;\n uwsgi_temp_path /tmp/uwsgi_temp;\n scgi_temp_path /tmp/scgi_temp;\n" /etc/nginx/nginx.conf && \
mkdir -p /var/cache/nginx && \
chown -R www-data:0 /var/cache/nginx && \
chmod -R g+w /var/cache/nginx

RUN mkdir -p tmp && \
echo "UPLOAD_DIR = '$PWD/tmp'" > at/config.py && \
echo "VERSION = '${VERSION}'" >> at/config.py && \
echo "REQUIRE_AUTH = False" >> at/config.py && \
echo "DT_LATEST_DRAFT_URL = 'https://datatracker.ietf.org/api/rfcdiff-latest-json'" >> at/config.py && \
echo "ALLOWED_DOMAINS = ['ietf.org', 'rfc-editor.org', 'github.com', 'githubusercontent.com', 'github.io', 'gitlab.com', 'gitlab.io', 'codeberg.page', 'httpwg.org', 'quicwg.org']" >> at/config.py && \
python3 version.py >> at/config.py && \
chown -R www-data:0 /usr/src/app/tmp

# cache configuration
RUN mkdir -p /tmp/cache/xml2rfc && \
mkdir -p /tmp/cache/refcache && \
mkdir /var/www/.cache && \
ln -sf /tmp/cache/xml2rfc /var/cache/xml2rfc && \
chown -R www-data:0 /tmp/cache /var/www/.cache
ENV KRAMDOWN_REFCACHEDIR=/tmp/cache/refcache


# COPY required files
COPY static /usr/share/nginx/html/
COPY api.yml /usr/share/nginx/html/
COPY docker/gunicorn.py /usr/src/app/
COPY docker/nginx-default-site.conf /etc/nginx/sites-available/default
COPY docker/supervisord.conf /etc/supervisor/
COPY requirements.dev.txt /usr/src/app/
COPY tests /usr/src/app/tests
COPY docker /usr/src/app/docker

CMD ["bash"]

0 comments on commit a2fef96

Please sign in to comment.