-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加了往 hyper.sh 容器平台的部署和升级脚本。现在 Discussion.Migrations 将同样以一个可执行程序的方式在容器…
…中与 Discussion.Web 一起发行,可参考 upgrade-from-existing.sh 中的调用方法。
- Loading branch information
Jijie Chen
committed
Sep 23, 2018
1 parent
1c3e09f
commit 9018351
Showing
11 changed files
with
175 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
oldVer=$1 | ||
newVer=$2 | ||
|
||
RED=`tput setaf 1` | ||
GREEN=`tput setaf 2` | ||
NC=`tput sgr0` # no color | ||
|
||
|
||
if [ "$newVer" == "" ] || [ "$oldVer" == "" ]; then | ||
echo "${RED}请指定要从哪个版本升级到哪个版本!${NC}" | ||
echo "${RED}比如,从第 001 升级到 003,请指定 deploy-on-hyper.sh 001 003${NC}" | ||
exit 1 | ||
fi | ||
|
||
|
||
new_image="jijiechen/dotnetclub:$newVer" | ||
|
||
if [ "$oldVer" == "0" ]; then | ||
# 首次安装时,创建 volume | ||
hyper volume create --size=10 --name clubdata | ||
|
||
hyper run -d --name volumes -v clubdata:/club-data --size S3 --restart always hyperhq/nfs-server | ||
|
||
hyper exec volumes mkdir /club-data/$newVer | ||
hyper exec volumes chmod -R 777 /club-data/$newVer | ||
hyper exec -i volumes tee /club-data/$newVer/appsettings.Production.json < ./src/Discussion.Web/appsettings.Production.json | ||
else | ||
# 从旧版本升级到新版本 | ||
hyper run --rm --name upgrade --volumes-from volumes --entrypoint "/club-app/upgrade-from-existing.sh" $new_image $oldVer $newVer | ||
fi | ||
|
||
|
||
# 运行新版本的程序 | ||
hyper run -d -p 80:5000 --name "club$newVer" \ | ||
--volumes-from volumes --size S4 --restart always \ | ||
-e "ASPNETCORE_contentRoot=/club-data/$newVer" --workdir /club-data/$newVer $new_image | ||
|
||
# 分配新的 fip | ||
fip=`hyper fip allocate --yes 1` | ||
hyper fip attach $fip "club$newVer" | ||
|
||
|
||
# 输出部署结果 | ||
echo "" | ||
echo "${GREEN}A new version ($new_image) is deployed at IP:$fip${NC}" | ||
|
||
# todo: your dns??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="FluentMigrator" Version="3.1.3" /> | ||
<PackageReference Include="FluentMigrator.Runner" Version="3.1.3" /> | ||
<PackageReference Include="FluentMigrator.Runner.SQLite" Version="3.1.3" /> | ||
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.1.0" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.IO; | ||
using FluentMigrator.Runner; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Discussion.Migrations.Supporting | ||
{ | ||
public static class SqliteMigrator | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var connectionString = args != null && args.Length > 0 ? args[0] : null; | ||
if (string.IsNullOrWhiteSpace(connectionString)) | ||
{ | ||
PrintError("Please specify a connection string for the Sqlite db."); | ||
Environment.Exit(1); | ||
return; | ||
} | ||
|
||
Console.WriteLine($"Starting migrating..."); | ||
|
||
try | ||
{ | ||
Migrate(connectionString, null); | ||
} | ||
catch (Exception e) | ||
{ | ||
PrintError(e.ToString()); | ||
Environment.Exit(4); | ||
} | ||
|
||
Console.ForegroundColor = ConsoleColor.Green; | ||
Console.WriteLine("Migrating completed successfully"); | ||
Console.ResetColor(); | ||
} | ||
|
||
static void PrintError(string message) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.Error.WriteLine(message); | ||
Console.ResetColor(); | ||
} | ||
|
||
|
||
public static void Migrate(string connectionString, Action<ILoggingBuilder> configureLogging) | ||
{ | ||
var services = CreateServices(connectionString, configureLogging); | ||
|
||
using (var scope = services.CreateScope()) | ||
{ | ||
UpdateDatabase(scope.ServiceProvider); | ||
} | ||
|
||
(services as IDisposable)?.Dispose(); | ||
} | ||
|
||
private static IServiceProvider CreateServices(string connectionString, Action<ILoggingBuilder> configureLogging) | ||
{ | ||
return new ServiceCollection() | ||
.AddFluentMigratorCore() | ||
.ConfigureRunner(rb => rb | ||
.AddSQLite() | ||
.WithGlobalConnectionString(connectionString) | ||
.ScanIn(typeof(CreateArticleTable).Assembly).For.Migrations()) | ||
.AddLogging(logging => | ||
{ | ||
logging.AddFluentMigratorConsole(); | ||
configureLogging?.Invoke(logging); | ||
}) | ||
.BuildServiceProvider(false); | ||
} | ||
|
||
|
||
private static void UpdateDatabase(IServiceProvider serviceProvider) | ||
{ | ||
var runner = serviceProvider.GetRequiredService<IMigrationRunner>(); | ||
runner.MigrateUp(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# this script is executed in an transitional upgrading image | ||
|
||
set -e | ||
|
||
oldVer=$1 | ||
newVer=$2 | ||
|
||
|
||
# todo: Make existing site readonly | ||
|
||
|
||
|
||
if [ ! -d /club-data/$newVer/ ]; then | ||
mkdir /club-data/$newVer/ | ||
chmod -R 777 /club-data/$newVer/ | ||
fi | ||
|
||
cp /club-data/$oldVer/appsettings.Production.json /club-data/$newVer/ | ||
cp /club-data/$oldVer/dotnetclub.db /club-data/$newVer/ | ||
|
||
|
||
dotnet /club-app/Discussion.Migrations.dll "Data Source=/club-data/$newVer/dotnetclub.db" | ||
|
||
|