Skip to content

Commit 10680c1

Browse files
dabatesdanielunderwood
authored andcommitted
Docker changes (Radarr#5)
* Docker Changes Initial changes - Refactor how the docker container is started - working on getting the startup / setup scripts working * Working on getting the docker to build and start correctly * Changes to the Docker files and scripts. It now brings both containers up. Runs the DB Migrations and sets everything up * Fixes to make Docker Work - Startup.cs : Added debug values for some Variables to make sure they are passing correctly - Dockerfile: refactored the build and added some directory removals (I've found they cause the build to error) - README.md : added info on docker usage - docker-compose : removed old entries * Refactor Refactored the docker-compose, as my in-experince with docker containers skewed how I did some things.. this shoule be more streamlined * Refactor for using ENV Variables This refactors the WebAPI Code so that it will use ENV variables if they are present * fixup! removes mysql port * Adds more debug info
1 parent 9ab1fad commit 10680c1

File tree

5 files changed

+53
-24
lines changed

5 files changed

+53
-24
lines changed

Dockerfile

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
FROM microsoft/dotnet:2.0-sdk
22
WORKDIR /app
33

4-
# copy csproj and restore as distinct layers
5-
COPY LidarrAPI/*.csproj ./
6-
RUN dotnet restore
7-
84
# copy everything else and build
95
COPY LidarrAPI/* ./
10-
RUN dotnet publish -c Release -o out
6+
COPY docker-services/LidarrAPI/docker-entrypoint.sh ./
7+
8+
# Windows screws with Line Endings, so do this to be 100% sure
9+
RUN sed -i 's/\o015/\n/g' docker-entrypoint.sh
10+
11+
# Run needed things on build
12+
RUN dotnet restore && dotnet publish -c Release -o out
1113

12-
ENTRYPOINT ["dotnet", "out/LidarrAPI.dll"]
14+
# Docker Entry
15+
ENTRYPOINT ["./docker-entrypoint.sh"]

LidarrAPI/Startup.cs

+13-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.Extensions.Configuration;
1111
using Microsoft.Extensions.DependencyInjection;
1212
using Microsoft.Extensions.Logging;
13+
using NLog;
1314
using NLog.Extensions.Logging;
1415
using NLog.Web;
1516
using Octokit;
@@ -20,21 +21,24 @@ namespace LidarrAPI
2021
{
2122
public class Startup
2223
{
23-
public Startup(IConfiguration configuration, IHostingEnvironment env)
24+
public Startup(IHostingEnvironment env)
2425
{
25-
Config = configuration;
26+
// Loading .NetCore style of config variables from json and environment
27+
var builder = new ConfigurationBuilder()
28+
.SetBasePath(env.ContentRootPath)
29+
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
30+
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
31+
.AddEnvironmentVariables();
32+
33+
Config = builder.Build();
2634
ConfigLidarr = Config.GetSection("Lidarr").Get<Config>();
2735

2836
env.ConfigureNLog("nlog.config");
29-
30-
// If env variables exist, read those in instead
31-
ConfigLidarr.Database = Environment.GetEnvironmentVariable("Database") ?? ConfigLidarr.Database;
32-
ConfigLidarr.DataDirectory = Environment.GetEnvironmentVariable("DataDirectory") ?? ConfigLidarr.DataDirectory;
33-
ConfigLidarr.ApiKey = Environment.GetEnvironmentVariable("ApiKey") ?? ConfigLidarr.ApiKey;
34-
ConfigLidarr.AppVeyorApiKey = Environment.GetEnvironmentVariable("AppVeyorApiKey") ?? ConfigLidarr.AppVeyorApiKey;
35-
3637
SetupDataDirectory();
3738
SetupDatadog();
39+
40+
Logger logger = LogManager.GetCurrentClassLogger();
41+
logger.Debug($"Config Variables\n----------------\nDataDirectory : {ConfigLidarr.DataDirectory}\nDatabase : {ConfigLidarr.Database}\nAPIKey : {ConfigLidarr.ApiKey}\nAppVeyorApiKey : {ConfigLidarr.AppVeyorApiKey}\n\n");
3842
}
3943

4044
public IConfiguration Config { get; }

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ This is the update API of [https://github.com/Lidarr/Lidarr](https://github.com/
66
## Development
77

88
If you want to work on **LidarrAPI.Update**, make sure you have [.NET Core 2.0 SDK](https://www.microsoft.com/net/download/core) installed and [Visual Studio 2017 RC](https://www.visualstudio.com/vs/visual-studio-2017-rc/).
9+
10+
## Using Docker
11+
12+
If you would like to use the docker setup we have for this project, follow these directions:
13+
- Setup Environment Variables
14+
- Make sure you set an environment variable PRIOR to running docker-compose up called `MYSQL_ROOT_PASSWORD` OR
15+
- Setup and .env file or another way of passing variables as documented here: [Docker Compose](https://docs.docker.com/compose/environment-variables/#the-env-file)
16+
17+
The most important thing is the `ApiKey`, the rest can be used **AS-IS**, but if the ApiKey is not set, fetching updates from AppVeyor and Github will not function correctly.

docker-compose.yml

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
version: '3'
22
services:
33
mysql:
4-
image: mysql
5-
4+
image: mysql/mysql-server
65
environment:
7-
- MYSQL_ROOT_PASSWORD=
8-
6+
- MYSQL_ROOT_PASSWORD
7+
- MYSQL_DATABASE=lidarrupdate
8+
- MYSQL_USER=root
9+
- MYSQL_PASSWORD=${MYSQL_ROOT_PASSWORD}
10+
911
lidarrupdate:
1012
build: .
11-
1213
ports:
13-
- "5001:5000"
14+
- "5000:5000"
1415

1516
links:
1617
- mysql
1718

1819
environment:
19-
- DataDirectory=/data
20-
- Database="server=127.0.0.1;user id=root;password=${MYSQL_ROOT_PASSWORD};database=lidarrupdate;CharSet=utf8mb4"
21-
- ApiKey=
20+
- Lidarr:DataDirectory=/data
21+
- Lidarr:Database=server=mysql;user id=root;password=${MYSQL_ROOT_PASSWORD};database=lidarrupdate;CharSet=utf8mb4
22+
- Lidarr:ApiKey=
2223
- ASPNETCORE_URLS=http://0.0.0.0:5000
2324

2425
volumes:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Entrypoint for the docker container
5+
6+
# First, we need to make sure the database is there
7+
echo "[Entrypoint-LidarAPI] Running Database Migrations"
8+
dotnet ef database update
9+
10+
#Second, start the Service
11+
echo "[Entrypoint-LidarAPI] Starting LidarrAPI Service"
12+
dotnet out/LidarrAPI.dll

0 commit comments

Comments
 (0)