Migrating from JAR to Docker¶
If you want to move to a Docker based installation, and you’ve already been running CodeScene for a while with the standalone JAR, you probably want to migrate your data to the new installation. This process involves:
Setting up the database in docker
Running a migration script to rewrite old paths in the database
Generating new SSH keys (if needed)
Step 1 differs depending on if you are running the built-in embedded H2 database or MySQL. Both processes are described below.
Note: we do not support Google repos or specifying a git repo from the local filesystem when running in docker. Such projects will be removed in the migration.
General information about getting started with Docker can be found at Docker Hub.
Step 1a: Embedded H2 database¶
Running using a built-in embedded H2 database is the default setting in CodeScene. A simple docker-compose.yml without any variables will do the trick:
version: '3' services: codescene: image: empear/codescene:latest ports: - 3003:3003 volumes: - codescene:/codescene volumes: codescene:
$ docker compose create $ docker compose cp <PATH TO OLD DB> codescene:/codescene/codescene.mv.db
The path to the old database file is either resources/caacs_enterprise.db.mv.db or set by the CODESCENE_DB_PATH environment variable.
Step 1b: MySQL database¶
We recommend making a copy of the old database before proceeding, because the migration script in the next step will alter the data. By making a copy you can easily go back to the JAR installation should you need to.
The docker container needs the right environment variables to connect to an external database. The variables are the same as when running the standalone JAR described in the installation guide.
Here is an example using docker compose:
version: '3' services: codescene: image: empear/codescene:latest ports: - 3003:3003 volumes: - codescene:/codescene environment: - CODESCENE_DB_ENGINE=mysql - CODESCENE_DB_HOST=<external host> - CODESCENE_DB_NAME=<db name> - CODESCENE_DB_USER=<user> - CODESCENE_DB_PASSWORD=<password> volumes: codescene:
Step 2: Running migration script¶
Because the old database contains paths to directories on the local filesystem where analysis results and cloned repos are stored, these paths need to be rewritten for the Docker installation.
Before starting CodeScene in Docker for the first time, run the docker-migration.sh script that is built into the docker image. With docker compose, we can first run the check command to check that we have access to the database, and which projects that will be migrated:
$ docker compose run --entrypoint "docker-migration.sh check" codescene
After that, we can run the migration:
$ docker compose run --entrypoint "docker-migration.sh migrate" codescene
Step 3: (Optional) SSH keys¶
Generate SSH keys for the new installation according to the documentation at Docker Hub.
At this point CodeScene should be ready to run. With docker compose we can start it like this:
$ docker compose up -d
Please note that you will need to re-run an analysis for your projects to be able to access the analysis dashboards. Also note that CodeScene will start to re-clone git repositories when starting up again so manual requests for analyses may be queued up for a while.