Skip to content

feat(docker): added docker-compose script #170

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -14,4 +14,11 @@ package-lock.json
.github/
/public
.min.js
.min.css
.min.css

#Dockerfile
.dockerignore
Dockerfile.dev
Dockerfile
docker-compose.yml
docker-compose.dev.yml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -118,6 +118,7 @@ package-lock.json

# misc
.DS_Store
.vscode
.env.local
.env.development.local
.env.test.local
9 changes: 8 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -14,4 +14,11 @@ package-lock.json
.github/
/public
.min.js
.min.css
.min.css

#Dockerfile
.dockerignore
Dockerfile.dev
Dockerfile
docker-compose.yml
docker-compose.dev.yml
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@

# Description: Docker container image recipe


FROM node:14.15.4-slim

LABEL maintainer="Fossology <fossology@fossology.org>"
@@ -37,4 +36,4 @@ RUN yarn

EXPOSE 3000

CMD [ "yarn", "start" ]
CMD [ "yarn", "start" ]
44 changes: 44 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# FOSSology Dockerfile

# Copyright (C) 2022 Vineet Vatsal (vineetvatsal09@gmail.com)

# SPDX-License-Identifier: GPL-2.0

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# Description: Docker container image recipe


FROM node:14.15.4-slim

EXPOSE 3000

LABEL maintainer="Fossology <fossology@fossology.org>"

ARG REACT_APP_SERVER_URL
ENV REACT_APP_SERVER_URL=$REACT_APP_SERVER_URL

ARG REACT_APP_HTTPS
ENV REACT_APP_HTTPS=$REACT_APP_HTTPS

RUN mkdir -p /usr/src/fossologyui
WORKDIR /usr/src/fossologyui

COPY package.json ./
COPY yarn.lock ./
RUN yarn install
ENV PATH /usr/src/fossologyui/node_modules/.bin:$PATH

RUN mkdir -p /usr/src/fossologyui/app
WORKDIR /usr/src/fossologyui/app
COPY . .
72 changes: 67 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -34,22 +34,84 @@ The UI Migration project is an effort focused on generating the new component-ba

### Docker

FOSSology comes with a Dockerfile allowing the containerized execution.
#### Development

Run the following commands inside the project directory.
FOSSology comes with a Dockerfile allowing for containerized execution.

```sh
This method only requires that you have the `Docker engine` and `docker-compose` installed on your machine.

- Added benefits to this method other than the ones that docker already provides is you are not confined to developing in the docker container. You can also develop using your local modules as defined above.

```zsh
docker-compose -f docker-compose.dev.yml pull fossology_server && docker-compose -f docker-compose.dev.yml up #Starts the react-dev-server on localhost:3000
```

On Windows you might have to forego the `&&` and run both commands individually.

Running the `docker-compose pull ...` command each time you run the docker container isn't required but recommended so as to get the latest fossology image.

This will start the react-dev-server on localhost on `port:3000`.

The docker image can then be used using http://IP_OF_DOCKER_HOST:3000/ user fossy password fossy. (IP_OF_DOCKER_HOST is generally localhost)

You can even run it detached in the background using the -d option.

```zsh
docker-compose -f docker-compose.dev.yml up -d
docker-compose logs #To view server logs
```

npm packages can be installed using `docker-compose exec`

```zsh
docker-compose -f docker-compose.dev.yml exec -w /usr/src/fossologyui fossologyui_server yarn add --save <package name> #Install npm package for react-dev-server
```

Once done developing, you can clean up running containers and networks using:

```zsh
docker-compose -f docker-compose.dev.yml down
```

#### Production

For production level deployment you can use:

```zsh
docker build \
-t fossologyui:react1.0 \
--build-arg REACT_APP_SERVER_URL="localhost/repo/api/v2" \
--build-arg REACT_APP_HTTPS="false" .
```

```sh
for building the image and then host the image using:

```zsh
docker run -p 3000:3000 fossologyui:react1.0
```

The docker image can then be used using `http://IP_OF_DOCKER_HOST:3000/` user `fossy` password `fossy`.
The docker image would then be hosted on http://IP_OF_DOCKER_HOST:3000/ user fossy password fossy. (IP_OF_DOCKER_HOST is generally localhost)

Alternatively, you can also deploy it using docker-compose:

```zsh
docker-compose up
```

You can even run it detached in the background using the -d option.

```zsh
docker-compose up -d
docker-compose logs #To view server logs
```

Deployed image can be pulled down using:

```zsh
docker-compose down
```

This will clean up running containers and networks.

### Project Setup

67 changes: 67 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# FOSSology docker-compose file

# Copyright (C) 2022 Vineet Vatsal (vineetvatsal09@gmail.com)

# SPDX-License-Identifier: GPL-2.0

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# Description: docker-compose file for development environment.


version: "3.9"

services:
fossologyui_server:
build:
context: .
dockerfile: Dockerfile.dev
args:
- REACT_APP_SERVER_URL=localhost/repo/api/v2
- REACT_APP_HTTPS=false
image: fossologyui:react1.0
environment:
- REACT_APP_SERVER_URL=localhost/repo/api/v2
- REACT_APP_HTTPS=false
command: ../node_modules/.bin/react-scripts start
ports:
- "3000:3000"
volumes:
- .:/usr/src/fossologyui/app:delegated
# bind-mounting these three files in will let you add packages during development without rebuilding
# for example, to add bower to your app while developing, just install it inside the container
# and then nodemon will restart. Your changes will last until you "docker-compose down" and will
# be saved on host for next build
# NOTE: this won't work on Docker Toolbox (virtualbox) which doesn't bind-mount single files
# docker-compose exec node npm install --save bower
- ./package.json:/usr/src/fossologyui/package.json
- ./package-lock.json:/usr/src/fossologyui/package-lock.json
- ./yarn.lock:/usr/src/fossologyui/yarn.lock
# this is a workaround to prevent host node_modules from accidently getting mounted in container
# in case you want to use node/npm both outside container for test/lint etc. and also inside container
# this will overwrite the default node_modules dir in container so it won't conflict with our
# /usr/src/fossologyui/node_modules location.
- notused:/usr/src/fossologyui/node_modules

fossology_server:
image: fossology/fossology:latest
ports:
- "8081:80"
volumes:
- repository:/srv/fossology/repository/
- database:/var/lib/postgresql/data

volumes:
notused:
repository:
database:
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# FOSSology docker-compose file

# Copyright (C) 2022 Vineet Vatsal (vineetvatsal09@gmail.com)

# SPDX-License-Identifier: GPL-2.0

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# Description: docker-compose file for production environment


version: "3.9"

services:
fossologyui_server:
build:
context: .
dockerfile: Dockerfile
args:
- REACT_APP_SERVER_URL=localhost/repo/api/v2
- REACT_APP_HTTPS=false
image: fossologyui:react1.0
environment:
- REACT_APP_SERVER_URL=localhost/repo/api/v2
- REACT_APP_HTTPS=false
ports:
- "3000:3000"
command: yarn start