Here are the steps to build Redmine 4.1.1 on Azure App Service. I try to use PaaS instead of IaaS. The prerequisites and notes for this article are itemized below.
You'll need an Azure subscription, resource group, and App Service plan to complete the steps in this article. How to create a subscription etc. is not explained here, so please refer to the explanation of Microsoft Docs.
--[Create Azure Free Account] 01 --[Manage resource groups using Azure portal] 02 --[Manage App Service Plans in Azure] 03
The procedure is divided into the following three steps. I wanted to automate it like Infrastructure as Code, but I mainly use the screen operation of Azure portal and CLI of Docker Desktop for Mac.
Create an Azure Database for MySQL server using the Azure portal or the like. Instructions for creating using the Azure portal are detailed in [Microsoft Docs Quick Start] 11(the same content is not reproduced in this article). Make a note of the server information created at this time, as it will be needed in the Redmine config/database.yml settings.
After creating the MySQL server, create a blank database. Set firewall rules appropriately so that you can connect to the server from the mysql client in your local environment or Azure Cloud Shell. The name of the database is arbitrary, but here it is redmine
.
Create a redmine database
user@Azure:~$ mysql --host={server name}.mysql.database.azure.com \
--user={login name}@{server name} -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 65486
Server version: 5.6.47.0 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> CREATE DATABASE redmine CHARACTER SET utf8mb4;
Query OK, 1 row affected (0.264 sec)
After creating the database, summarize the database.yml settings (database name, server name, login name, password) that will be required in the subsequent steps.
config/database.yml
production:
adapter: mysql2
database: {database name of redmine}
host: {server name}.mysql.database.azure.com
username: {login name}@{server name}
password: {password}
encoding: utf8mb4
Create the tables required for Redmine operation in the blank database created in Azure Database for MySQL. Install Redmine on your laptop or other system according to the [redmine.org Installation Guide] 21 to use the Rake migration file (rake db: migrate).
This article uses macOS, but if you try to use Ruby that comes pre-installed on your system, you will likely get errors related to dependent packages such as [nokogiri] 22 and [tiny_tds] 23, so [Docker] I'm using Desktop for Mac 24 and [ruby: 2.6 Docker Container] 25
Run rake migration file
% docker pull ruby:2.6
% docker run -it -p 3000:3000 ruby:2.6 bash
## redmine.Get the archive file from org
/# cd /usr/local/src/
/usr/local/src# wget https://www.redmine.org/releases/redmine-4.1.1.tar.gz
/usr/local/src# tar xfz redmine-4.1.1.tar.gz
/usr/local/src# cd redmine-4.1.1
##Set the connection information of Azure Database for MySQL
##In the here document because vi could not be used in ruby's Docker container
/usr/local/src/redmine-4.1.1# cat -<<EOF > config/database.yml
production:
adapter: mysql2
database: {database name of redmine}
host: {server name}.mysql.database.azure.com
username: {login name}@{server name}
password: {password}
encoding: utf8mb4
EOF
##Install dependent packages
/usr/local/src/redmine-4.1.1# bundle install --without development test
##Create a session store secret
/usr/local/src/redmine-4.1.1# bundle exec rake generate_secret_token
##Create a schema object and load the default configuration data
/usr/local/src/redmine-4.1.1# bundle exec rake db:migrate RAILS_ENV=production
/usr/local/src/redmine-4.1.1# bundle exec rake redmine:load_default_data RAILS_ENV=production REDMINE_LANG=ja
When the build with rake is complete, the database build is complete. At this point, you should be able to see it working on your local WEBrick web server (localhost: 3000) and the Azure Database for MySQL database server.
Operation check by WEBrick
/usr/local/src/redmine-4.1.1# bundle exec rails server webrick -e production
=> Booting WEBrick
=> Rails 5.2.4.2 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
INFO WEBrick 1.4.2
INFO ruby 2.6.6 (2020-03-31) [x86_64-linux]
INFO WEBrick::HTTPServer#start: pid=10010 port=3000
At this time, change the admin user password and application title from the default values. The admin user during initial build can log in with login: admin, password: admin
as described in [Installation Guide] 26.
Then go back to the Azure portal and create an App Service. Here, the image source is [Docker Hub Redmine] [31], and the price level of the App Service plan is F1 which is free.
Setting items | Set value |
---|---|
App Service name | |
Release(Publish) | Docker Container |
option | Single Container |
Image source | Docker Hub |
Type of access | Public |
Images and tags(Image:Tag) | redmine:latest (4.1.1) |
Immediately after creating from the official Redmine image of Docker Hub, the database adapter is SQLite3. It works with SQLite3 as it is, but set the MySQL connection information in the application settings of App Service so that the Azure Database for MySQL built in the previous step is referenced as the database server.
App Service application settings | Set value |
---|---|
REDMINE_DB_DATABASE | <MySQL database name> |
REDMINE_DB_ENCODING | utf8mb4 |
REDMINE_DB_MYSQL | <MySQL server name> .mysql.database.azure.com |
REDMINE_DB_USERNAME | <MySQL login name>@<MySQL server name> |
REDMINE_DB_PASSWORD | <MySQL password> |
After entering the settings, save your changes and restart the application. Details on how to add application settings in the Azure portal can be found in [Microsoft Docs] [32].
After restarting the application, if you can connect to Azure Database for MySQL from App Service, you can confirm that the Database adapter on the "Administration/Information" screen is Mysql2. If you can't connect to the MySQL server from App Service, check carefully to see if it's denied by your firewall rules.
Default adapter: SQLite3 | Adapter after setting change: Mysql2 |
---|---|
If you're experiencing any errors, you may be able to find the cause from the blade logs in the Container settings in the Azure portal.
[10]: Create # azure-database-for-mysql- [20]: Build a database of # redmine- [30]: Build # web-app-for-containers- [31]: https://hub.docker.com/_/redmine/ [32]: https://docs.microsoft.com/azure/app-service/configure-common
Recommended Posts