Skip to content
This repository was archived by the owner on Dec 29, 2021. It is now read-only.

Commit 4236377

Browse files
author
Neel Kamath
authored
Use non-root user in Dockerfile (#15)
1 parent a69358b commit 4236377

File tree

9 files changed

+19
-22
lines changed

9 files changed

+19
-22
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ s2v_old/
22
.idea/
33
redoc-static.html
44
.pytest_cache/
5-
venv/
5+
venv/
6+
__pycache__/

.gitlab-ci.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ test-server:
2929
test-spec:
3030
stage: test
3131
image: node
32-
script:
33-
- npm i -g @stoplight/spectral
34-
- spectral lint docs/openapi.yaml
32+
script: npx @stoplight/spectral lint docs/openapi.yaml
3533

3634
build-image:
3735
stage: build
@@ -52,9 +50,7 @@ build-image:
5250
build-docs:
5351
stage: build
5452
image: node
55-
script:
56-
- npm i -g redoc-cli
57-
- redoc-cli bundle docs/openapi.yaml --title 'spaCy'
53+
script: npx redoc-cli bundle docs/openapi.yaml --title 'spaCy Server'
5854
artifacts:
5955
paths: [redoc-static.html]
6056
only: [master]

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.7
1+
FROM python:3.8
22
WORKDIR /app
33
ENV PYTHONUNBUFFERED 1
44
COPY requirements.txt .
@@ -8,4 +8,6 @@ COPY s2v_old/ s2v_old/
88
EXPOSE 8000
99
HEALTHCHECK --timeout=2s --start-period=2s --retries=1 \
1010
CMD curl -f http://localhost:8000/health_check
11+
RUN useradd user
12+
USER user
1113
CMD ["uvicorn", "main:app", "--host", "0.0.0.0"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This project provides industrial-strength NLP via [spaCy](https://spacy.io/) and
1010

1111
Install [Docker](https://hub.docker.com/search/?type=edition&offering=community).
1212

13-
The container `EXPOSE`s port `8080`. To serve at `http://localhost:8080`, run `docker run --rm -p 8080:8080 neelkamath/spacy-server`.
13+
The container `EXPOSE`s port `8000`. To serve at `http://localhost:8000`, run `docker run --rm -p 8000:8000 neelkamath/spacy-server`.
1414

1515
You can find specific versions on the [Docker Hub repository](https://hub.docker.com/repository/docker/neelkamath/spacy-server/tags?page=1).
1616

docker-compose.test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
version: '3.7'
22
services:
33
app:
4-
command: sh setup.sh 'pytest'
4+
command: sh setup.sh pytest

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# It is not possible to use a Docker volume to cache the dependencies because subsequent usage of the volume
22
# occasionally gets corrupted for an unknown reason. Hence, a virtual environment is to be used instead. It is known
33
# that virtual environments aren't needed in Docker because isolation is already provided; we use it as a cache instead.
4+
45
version: '3.7'
56
services:
67
app:
7-
image: python:3.7
8+
image: python:3.8
89
working_dir: /app
910
volumes:
1011
- type: bind

docs/CONTRIBUTING.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@ If you're forking the repo to develop the project as your own and not just to se
66

77
1. Install [Docker](https://hub.docker.com/search/?type=edition&offering=community).
88
1. If you are generating documentation or testing the spec, install [node.js](https://nodejs.org/en/download/).
9-
1. If you are generating documentation, run `npm i -g redoc-cli`.
10-
1. If you are testing the spec, run `npm i -g @stoplight/spectral`.
119
1. Clone the repository using one of the following methods.
1210
- SSH: `git clone [email protected]:neelkamath/spacy-server.git`
1311
- HTTPS: `git clone https://github.com/neelkamath/spacy-server.git`
14-
1. `cd spacy-server`
15-
1. Download the [pretrained vectors](https://github.com/explosion/sense2vec/releases/download/v1.0.0/s2v_reddit_2015_md.tar.gz).
16-
1. Extract the pretrained vectors. You should get a directory named `s2v_old`.
12+
1. Download the [pretrained vectors](https://github.com/explosion/sense2vec/releases/download/v1.0.0/s2v_reddit_2015_md.tar.gz). After extracting them into the project's directory, uou should get a directory named `s2v_old`.
1713

1814
## [Developing](developing.md)

docs/developing.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
### Development
66

77
```
8-
docker-compose up --build
8+
docker-compose -p dev up --build
99
```
1010

1111
The server will be running on `http://localhost:8000`, and has automatic reload enabled.
1212

1313
### Testing
1414

1515
```
16-
docker-compose -f docker-compose.yml -f docker-compose.test.yml up --build --abort-on-container-exit --exit-code-from app
16+
docker-compose -p test -f docker-compose.yml -f docker-compose.test.yml \
17+
up --build --abort-on-container-exit --exit-code-from app
1718
```
1819

1920
### Production
@@ -31,15 +32,15 @@ The container `EXPOSE`s port `8000`. To serve at `http://localhost:8080`, run `d
3132
### Testing
3233

3334
```
34-
spectral lint docs/openapi.yaml
35+
npx @stoplight/spectral lint docs/openapi.yaml
3536
```
3637

3738
## Documentation
3839

3940
### Developing
4041

4142
```
42-
redoc-cli serve docs/openapi.yaml -w
43+
npx redoc-cli serve docs/openapi.yaml -w
4344
```
4445

4546
Open `http://127.0.0.1:8080` in your browser.
@@ -49,7 +50,7 @@ The documentation will automatically rebuild whenever you save a change to `docs
4950
### Production
5051

5152
```
52-
redoc-cli bundle docs/openapi.yaml -o redoc-static.html --title 'spaCy Server'
53+
npx redoc-cli bundle docs/openapi.yaml -o redoc-static.html --title 'spaCy Server'
5354
```
5455

5556
Open `redoc-static.html` in your browser.

setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
python -m venv venv
66
. venv/bin/activate
77
pip install -r requirements.txt
8-
$1
8+
$1

0 commit comments

Comments
 (0)