Skip to content

Commit dfefefe

Browse files
author
Kalle Norrestam
committed
Update when changing docker image
1 parent 2d30edb commit dfefefe

File tree

8 files changed

+86
-338
lines changed

8 files changed

+86
-338
lines changed

README.md

Lines changed: 39 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
# CodeScene on Docker
1+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
2+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3+
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
4+
5+
- [Overview](#overview)
6+
- [Install](#install)
7+
- [Generate a self-signed certificate](#generate-a-self-signed-certificate)
8+
- [Provide a custom SSL certificate](#provide-a-custom-ssl-certificate)
9+
- [Path prefix](#path-prefix)
10+
- [Run](#run)
11+
- [Run CodeScene behind the reverse proxy](#run-codescene-behind-the-reverse-proxy)
12+
- [Use](#use)
13+
- [Stop](#stop)
14+
- [License, Liability & Support](#license-liability--support)
15+
- [Analyze this this project on CodeScene](#analyze-this-this-project-on-codescene)
16+
17+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
18+
19+
# Overview
220

321
This repository is an example of how to run CodeScene in a Docker
422
instance behind an nginx reverse proxy. Even if you are not using Docker, the
523
nginx configuration may be helpful for running CodeScene behind nginx.
624

725
`docker-compose` is used here to run two Docker containers, one running
826
nginx, the other with CodeScene itself. The [CodeScene
9-
docker image](https://hub.docker.com/r/empear/ubuntu-onprem) can also be used by itself to
27+
docker image](https://hub.docker.com/r/empear/codescene) can also be used by itself to
1028
run CodeScene directly.
1129

12-
## Install
30+
# Install
1331

1432
This assumes that you have a working Docker installation.
1533

@@ -18,163 +36,23 @@ Clone this repository and go to the top level directory.
1836
git clone git@github.com:empear-analytics/docker-codescene-nginx-self-signed-ssl.git
1937
cd docker-codescene-nginx-self-signed-ssl
2038

21-
### Prepare the host and reverse proxy configuration for Letsencrypt SSL certificate
39+
To use it you have to either generate a self-signed certificate, or provide a real certificate.
2240

23-
Install certbot on the host according to the instructions found here: https://certbot.eff.org/lets-encrypt/ubuntubionic-other
24-
Replace `**domain_name**` with your correct domain name in docker-nginx/nginx.conf
25-
26-
The complete code is available in the `using_letsecrypt_ssl` branch - see https://github.com/empear-analytics/docker-codescene-nginx-self-signed-ssl/commit/1db5245b40b10ee954e3b23261f40b6e29a4b665.
27-
28-
## Build
29-
30-
The reverse proxy using Nginx is built like this:
31-
32-
docker build -t reverseproxy docker-nginx/
33-
34-
The CodeScene image is available from [Docker Hub](https://hub.docker.com/r/empear/ubuntu-onprem/).
35-
36-
If you want to use a specific version of CodeScene, you can add a tag in the `docker-compose.yml`:
41+
## Generate a self-signed certificate
3742

43+
Generate a self-signed certificate in the `nginx/conf.d` folder with a command like
3844
```
39-
image: empear/ubuntu-onprem:latest
45+
openssl req -subj '/CN=localhost' -x509 -newkey rsa:4096 -nodes \
46+
-keyout nginx/conf.d/mycert.key \
47+
-out nginx/conf.d/mycert.crt -days 365
4048
```
4149

42-
## Run
43-
44-
### Run CodeScene behind the reverse proxy
45-
46-
Use `docker-compose` to start both instances:
47-
48-
docker-compose up -d
49-
50-
### Run CodeScene by itself without the reverse proxy:
51-
52-
docker pull empear/ubuntu-onprem
53-
docker run -i -t -p 3003 \
54-
--name myname \
55-
--mount type=bind,source=$PWD/codescene,destination=/codescene \
56-
empear/ubuntu-onprem
57-
58-
To connect to this instance:
59-
60-
docker exec -i -t myname /bin/bash
61-
62-
63-
### Bind mount and/or Docker volume
64-
65-
In both the reverse proxy setup and the standalone version, the
66-
`/codescene` directory in the container is bound to the local
67-
`codescene` subdirectory. It will contain two directories, `repos` and
68-
`analyses` that are used to store Git repositories and the analysis
69-
result files that CodeScene produces. CodeScene's internal database is
70-
also stored in `/codescene`, as well as a logfile. By using these directories, your data
71-
will be persisted beyond the life of the Docker container.
72-
73-
Both the standalone command presented above and the `docker-compose` configuration use the `bind` mount type, for
74-
ease of demonstration and debugging. In a production setting, [Docker
75-
volumes](https://docs.docker.com/storage/volumes) would be a better
76-
solution.
7750

78-
The configuration presented here uses CodeScene's optional environment
79-
variables `CODESCENE_ANALYSIS_RESULTS_ROOT` and
80-
`CODESCENE_CLONED_REPOSITORIES_ROOT`. Their purpose is to ensure that users cannot create
81-
repositories or store analysis results outside of the `/codescene`
82-
directory. In conjunction with the `CODESCENE_DB_PATH`, we can be sure
83-
that all the necessary data for persisting CodeScene is in a single,
84-
easy-to-manage location. You can of course adjust these variables to
85-
fit your specific needs.
51+
## Provide a custom SSL certificate
52+
Place the ssl certificate and private key files in the *nginx/conf.d* folder to make them accessible in the nginx container.
53+
Update the *nginx/conf.d/reverseproxy.conf* file with `ssl_certificate` and `ssl_certificate_key` set to your certificate and key file names, and with `server_name` set to match your certificate.
8654

87-
Whether you use volumes or bind mounts, they must be passed to the
88-
Docker container at run time.
89-
90-
In the full reverse proxy setup using `docker-compose`, this is done
91-
in the `volumes` stanza of the configuration. The
92-
[`docker-compose.yml`](docker-compose.yml) file in this repository
93-
uses a Docker volume. To use a bind mount with `docker-compose`, or
94-
for more detailed instructions, please refer to the documentation
95-
[here](https://docs.docker.com/compose/compose-file/#volumes).
96-
97-
For the standalone configuration using a bind mount, see [Run
98-
CodeScene by itself without the reverse
99-
proxy](#run-codescene-by-itself-without-the-reverse-proxy). To use a
100-
Docker volume in the standalone configuration, you must first [create
101-
a volume](https://docs.docker.com/storage/volumes/#create-and-manage-volumes):
102-
103-
docker volume create codescene-volume
104-
105-
This volume can then be referenced when starting the Docker container:
106-
107-
docker run -i -t -p 3003 \
108-
--name myname \
109-
--mount type=volume,source=codescene-volume,target=/codescene \
110-
empear/ubuntu-onprem
111-
112-
Please refer to the [Docker documentation](https://docs.docker.com/storage/volumes)
113-
for instructions on managing your Docker volumes.
114-
115-
116-
### Authentication for remote Git repositories
117-
118-
To analyze code located on remote servers, CodeScene needs to be able
119-
to clone it with Git. For public repositories, cloning via `https` is
120-
sufficient. Private repositories will require authentication
121-
credentials, for which SSH keys are the recommended form. (For
122-
example, including user credentials in Git URLs is inherently insecure
123-
for requests of an open network.)
124-
125-
However, it can be tricky to communicate SSH credentials to a Docker
126-
container in a way that allows CodeScene to run unattended. Here are
127-
some options.
128-
129-
#### Keys without a passphrase
130-
131-
If you are comfortable using SSH keys that do not require a
132-
passphrase, the simplest solution is to bind a valid `.ssh` directory
133-
on the host system to `/root/.ssh` inside the container.
134-
135-
With the standalone setup, this would mean supplying an additional
136-
`--mount` argument to `docker run`, something like:
137-
138-
```
139-
--mount type=bind,source=$HOME/codescene-git-keys,destination=/root/.ssh
140-
```
141-
142-
With the `docker-compose` solution, you would add the following to the
143-
`volumes` section of the `codescene` stanza:
144-
145-
```
146-
-"${HOME}/codescene-git-keys:/root/.ssh"
147-
```
148-
149-
The directory at `$HOME/codescene-git-keys` could be tested outside of
150-
Docker to be sure that the SSH connection works correctly. Make sure
151-
that `known_hosts` contains a reference to the servers you will be
152-
cloning from.
153-
154-
#### GitHub deploy keys
155-
156-
For greater security, if your remote code is on GitHub, the solution
157-
above could be combined with GitHub's [deploy keys](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys).
158-
159-
#### Linux host: ssh-agent forwarding
160-
161-
When running on a Linux host, it may be possible to forward the host
162-
machine's `ssh-agent` to the Docker container by mounting a volume
163-
corresponding to $SSH_AUTH_SOCK (untested):
164-
165-
```
166-
--mount type=bind,source=$(dirname $SSH_AUTH_SOCK),destination=$(dirname $SSH_AUTH_SOCK) \
167-
-e SSH_AUTH_SOCK=$SSH_AUTH_SOCK
168-
```
169-
170-
#### Dedicated ssh-agent containers
171-
172-
You may be able to use a dedicated Docker container to store SSH credentials. See:
173-
174-
- [uber-common/docker-ssh-forward](https://github.com/uber-common/docker-ssh-agent-forward)
175-
- [nadeas/ssh-agent](https://github.com/nardeas/ssh-agent)
176-
177-
### Path prefix
55+
## Path prefix
17856

17957
In some situations, it may be necessary to run CodeScene under a path
18058
rather than at the root, eg. `example.com/codescene` rather than
@@ -196,79 +74,34 @@ location /codescene/ {
19674
}
19775
```
19876

77+
# Run
19978

79+
## Run CodeScene behind the reverse proxy
20080

201-
### Memory settings
202-
203-
To adjust memory settings for CodeScene running inside a container,
204-
you can set the `JAVA_OPTIONS` environment variable.
205-
206-
To set "max heap" explicitly use `-Xmx`:
207-
208-
```
209-
# with explicit max memory => notice that -m 500M is ignored
210-
docker run -p3103:3003 -m 500M -e JAVA_OPTIONS='-Xmx300m' --name codescene empear/ubuntu-onprem
211-
VM settings:
212-
Max. Heap Size: 300.00M
213-
Ergonomics Machine Class: server
214-
Using VM: OpenJDK 64-Bit Server VM
215-
```
216-
217-
To let the JVM autodetect default settings based on the container's memory:
218-
219-
```
220-
# with experimental options and autodetection
221-
# note that -XX:+UseCGroupMemoryLimitForHeap has been deprecated
222-
docker run -p3103:3003 -m 500M -e \
223-
JAVA_OPTIONS='-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=2' \
224-
--mount type=bind,source=$PWD/codescene,destination=/codescene \
225-
--name codescene empear/ubuntu-onprem
226-
VM settings:
227-
Max. Heap Size (Estimated): 222.50M
228-
Ergonomics Machine Class: server
229-
Using VM: OpenJDK 64-Bit Server VM
230-
```
231-
232-
Please note, that
233-
[support for `-XX:+UseCGroupMemoryLimitForHeap` has been deprecated in JDK 10](https://bugs.openjdk.java.net/browse/JDK-8194086)
234-
and is no longer needed.
81+
Use `docker-compose` to start both instances:
23582

236-
For more details, see
237-
[Java inside docker: What you must know to not FAIL](https://developers.redhat.com/blog/2017/03/14/java-inside-docker/).
83+
docker-compose up -d
23884

239-
Ppre
240-
### Timezones
24185

242-
CodeScene, in general, uses default system's timezone.
243-
In our docker image we set the default timezone explicitly to UTC via the `CODESCENE_TIMEZONE` env var.
244-
This can be overriden when the docker image is run:
245-
```
246-
docker run -p3003 -e CODESCENE_TIMEZONE='Europe/Stockholm' empear/ubuntu-onprem
247-
```
248-
Note that if you use docker-compose you need to leave out quotes:
249-
```
250-
environment:
251-
- CODESCENE_TIMEZONE=Europe/Stockholm
252-
```
25386

254-
### Use
87+
## Use
25588

25689
Browse to https://localhost. In order to use CodeScene, you will need a
25790
license. You can get a license on the [Empear Customer Portal](https://portal.empear.com/).
25891
For more information about CodeScene, see the [CodeScene Documentation](https://docs.enterprise.codescene.io/).
25992

260-
### Stop
93+
## Stop
26194

26295
To stop the reverse proxy:
26396

26497
docker-compose down
26598

26699

267-
### License, Liability & Support
100+
# License, Liability & Support
268101

269102
* The contents of this repository are provided under the [MIT License](https://github.com/empear-analytics/docker-codescene-nginx-self-signed-ssl/blob/master/LICENSE.md). Other licences may apply to the software contained in the Docker images referenced here.
270103

271104

272-
### Analyze this this project on CodeScene
105+
# Analyze this this project on CodeScene
273106

274107
[![](https://codescene.io/projects/2554/status.svg) Get more details at **codescene.io**.](https://codescene.io/projects/2554/jobs/latest-successful/results)

docker-compose.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
version: '3.2'
22

33
services:
4-
reverseproxy:
5-
build: docker-nginx
6-
ports:
7-
- 443:443
8-
restart: always
4+
reverseproxy:
5+
depends_on:
6+
- codescene
7+
image: nginx:1.19
8+
ports:
9+
- 443:443
10+
restart: always
11+
volumes:
12+
- ./nginx/conf.d:/etc/nginx/conf.d
913

10-
codescene:
11-
depends_on:
12-
- reverseproxy
13-
image: empear/ubuntu-onprem:latest
14-
restart: always
15-
volumes:
16-
- "./codescene:/codescene"
14+
codescene:
15+
image: empear/codescene:latest
16+
restart: always
17+
volumes:
18+
- ./codescene:/codescene
1719
# environment:
1820
# raise codescene log level for troubleshooting
1921
# - CODESCENE_LOG_LEVEL=DEBUG

docker-nginx/Dockerfile

Lines changed: 0 additions & 29 deletions
This file was deleted.

docker-nginx/LICENSE.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

docker-nginx/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docker-nginx/docker-entrypoint.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)