dev
Dockerfile1.0.0
latest
Dockerfile
L10n (pronounced Lion) is an on premises web application that allows you to store and search for known good string translations that you orginization has already translated.
L10n allows you to search for and input phrases that have known good translations in multiple other languages so you can save the turn around time of getting phrases translated and vetted by reusing pre-translated and vetted phrases your organization has already used.
When inputting new phrases you provide the local language version of the phrase (in my case English) and a comment explaining the context of the phrase, something that explains the usage of the phrase to help translators choose which version of a word to use. Then once you have translations which you know are good for your context and the target language you can add the translations of the phrase. You can add one translated form of a phrase per target language; Not all phrases need to be translated into each target langauge and you can add or update translations at any time.
To learn more about L10n or to contibute to it see Project L10n
docker run -e SECRET_KEY_BASE=***** -e L10N_DATABASE=l10n_production L10N_DATABASE_USER=l10nadmin -e L10N_DATABASE_PASSWORD=**** -e DATABASE_URL=mysql2://l10ndbserver.local:3306/l10n_production l10n:latest
This will create a container running the latest version of L10n that will connect to a MySQL server to store all translated phrases inputted into L10n.
This means that all the data will be presisted in the database meaning it would be safe to destory the container and spin up a new one.
In the above example the sql server is located at address l10ndbserver.local
and the database name is l10n_production
.
This Dockerfile
exposes a few environment variables which you will need to set to configure L10n correctly.
- SECRET_KEY_BASE - L10n will use this 128 character key to verify the integrity of signed cookies. For instructions on how to generate a secret key see below.
- DATABASE_URL - This is the url L10n will use to connect to the database. Example:
mysql2://mysqlserver.local/somedatabase
- L10N_DATABASE - This is the name of the database L10n will use. This database needs to exist and be setup on the sql server L10n is connecting to.
- L10N_DATABASE_USER - This is the user that L10n will use when connecting to the database.
- L10N_DATABASE_PASSWORD - This is the password L10n will use when connecting to the database.
- This
Dockerfile
expects you to have a running MySQL database server which the container generated by this image can access. - This
Dockerfile
expects you to have already run the migration scripts and seed scripts on the database. See below for instructions.
The L10n image has a tool called rake
installed which can be used to generate a secret key.
You can create your own key but by using rake
you get a hard to crack random character string.
To access this tool start a new container using the L10n image.
$ docker run --name secret_gen -d l10n:latest
This will bring up a container with L10n hosted on it. The L10n Web User Interface (WUI) will report a problem as it was not able to connect to the database seeing how we didn't set the environment variables but that is ok for now. Next attach to that running containers terminal.
$ docker exec -it secret_gen bash
Now we are running in the container which has rake
installed.
Execute the following command to generate a new secret key.
# rake secret
Copy the generated key and use it to set the SECRET_KEY_BASE
when brining up a new L10n container.
You can now exit and remove this container # exit
then $ docker rm secret_gen
It is expected that you have setup a MySQL database server, created the appropriate L10n database and granted permissions to the user L10n will use to read/write to it.
You can setup the database server using the offical MySQL Docker image, see below for a docker-compose
file example.
The L10n image has a tool called rake
which has a sub command that can create the required tables within the L10n database.
It can also be used to upgrade an existing database to a newer version via migrations.
To setup your existing L10n database you first need to bring up a container using the L10n image.
$ docker run --name database_gen -d l10n:latest
This will bring up a container with L10n hosted on it. The L10n Web User Interface (WUI) will report a problem as it was not able to connect to the database seeing how we didn't set the environment variables but that is ok for now. Next attach to that running containers terminal.
$ docker exec -it database_gen bash
Now we are running in the container which has rake
installed.
Execute the following command to create the required tables in the database.
# rake db:migrate
This command will either create the tables if they don't exist or alter them to conform to the schema in the latest version of L10n.
Note: Its important that you use the same image tag for populating the database that you are for hosting L10n otherwise you'll get a missmatch between the database and the L10n applicaiton.
Note: It is safe to run rake db:migrate
multiple times as it will only execute what migrations have not already been run.
If you just setup a new database you may want to seed it with default entries. As of version 1 seeding is optional as they just pre-populate L10n with a set of target languages.
# rake db:seed
Note: It is safe to run rake db:seed
multiple times as it will only insert entries in tables who are still empty. If they have records it assumes the table is already seeded.
You can now exit and remove this container # exit
then $ docker rm database_gen
At this point the database is setup and ready to be used by a L10n container. Start a new L10n container ensuring to populate the required environment variables.
docker run -e SECRET_KEY_BASE=***** -e L10N_DATABASE=l10n_production L10N_DATABASE_USER=l10nadmin -e L10N_DATABASE_PASSWORD=**** -e DATABASE_URL=mysql2://l10ndbserver.local:3306/l10n_production l10n:latest
If you do not already have a L10n database setup and want to host it via another Docker container you can use docker-compose
to create virtual service.
Your compose file can use the offical MySQL image to create a database container for L10n to use, the offical image supports enviornment variables to define the database and user you want and the image will crate the database and set its permissions when creating the container.
db:
container_name: l10ndb
image: mysql:5.7.12 # Offical MySQL Image
environment:
- MYSQL_ROOT_PASSWORD=myrootpassword
- MYSQL_PASSWORD=myl10npassword # Same as L10N_DATABASE_PASSWORD
- MYSQL_USER=l10admin # Same as L10N_DATABASE_USER
- MYSQL_DATABASE=l10n_production # Same as L10N_DATABASE
volumes:
- /mnt/DB/l10ndb:/var/lib/mysql # This saves the database files to the host so you can destroy the l10ndb container and not loose data
command: [mysqld, --character-set-server=utf8mb4, --collation-server=utf8mb4_unicode_ci] # These flags add unicode support for languages such as Japanese and Russian
restart: always # If the container crashes restart it
The L10n container can be brough up in the same way as we stated above, just set a few environment variables; however,
to save you the trouble of brining up L10n containers just so you can run rake db:migrate
and rake db:seed
you can run those commands just before you start up the L10n server.
web:
container_name: l10n
image: l10n:latest
environment:
- SECRET_KEY_BASE=mySuperSecretKeyThatYouCanNeverGuess
- L10N_DATABASE=l10n_production
- L10N_DATABASE_USER=l10nadmin
- L10N_DATABASE_PASSWORD=myl10npassword
- DATABASE_URL=mysql2://l10ndb:3306/l10n_production
ports:
- "8080:3000" # Expose L10n's WUI on http://localhost:8080
links:
- db:l10ndb # Setup virtual network between this container and l10ndb
command: bash -c "rake db:migrate && rake db:seed && rails s -p 3000 -b '0.0.0.0'"
restart: always # If the container crashes restart it
Bug reports and pull requests are welcome on GitHub at https://github.com/bvanderlaan/L10n-Docker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The code is available as open source under the terms of the Apache License, version 2.0.