Skip to content

Commit

Permalink
docker-compose HTTPS fix (ivanpaulovich#232)
Browse files Browse the repository at this point in the history
* docker-compose HTTPS fix
  • Loading branch information
ivanpaulovich authored Sep 15, 2020
1 parent 9aece74 commit 2d889c6
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 194 deletions.
11 changes: 6 additions & 5 deletions .docker/docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version: '3.4'

services:
# nginx:
# volumes:
# - ~/.aspnet/https:/https:ro
nginx:
volumes:
- ../.docker/https/localhost.crt:/etc/ssl/certs/localhost.crt:ro
- ../.docker/https/localhost.key:/etc/ssl/private/localhost.key:ro
accounts-api:
environment:
- ASPNETCORE_ENVIRONMENT=Production
Expand All @@ -13,7 +14,7 @@ services:
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/localhost.pfx
- PersistenceModule__DefaultConnection=Server=sql1;User Id=sa;Password=<YourStrong!Passw0rd>;Database=Accounts;
volumes:
- ~/.aspnet/https:/https:ro
- ../.docker/https:/https:ro
identity-server:
environment:
- ASPNETCORE_ENVIRONMENT=Production
Expand All @@ -22,7 +23,7 @@ services:
- ASPNETCORE_Kestrel__Certificates__Default__Password=MyCertificatePassword
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/localhost.pfx
volumes:
- ~/.aspnet/https:/https:ro
- ../.docker/https:/https:ro
wallet-spa:
stdin_open: true # docker run -i
tty: true # docker run -t
Expand Down
3 changes: 3 additions & 0 deletions .docker/init-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
dotnet tool update --global dotnet-ef --version 3.1.8
dotnet ef database update --project ../accounts-api/src/Infrastructure --startup-project ../accounts-api/src/WebApi
24 changes: 0 additions & 24 deletions .docker/localhost.crt

This file was deleted.

28 changes: 0 additions & 28 deletions .docker/localhost.key

This file was deleted.

19 changes: 3 additions & 16 deletions .docker/makecert.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
#!/bin/bash
openssl req -x509 -newkey rsa:2048 -keyout localhost.key -out localhost.crt -days 365 -nodes -config ./ssl-selfsigned.cnf
openssl pkcs12 -export -out localhost.pfx -inkey localhost.key -in localhost.crt -name "Localhost selfsigned certificate" -password pass:MyCertificatePassword
rm ~/.aspnet/https/localhost.key
rm ~/.aspnet/https/localhost.crt
rm ~/.aspnet/https/localhost.pfx
rm ../wallet-spa/localhost.key
rm ../wallet-spa/localhost.crt
rm ../nginx/localhost.key
rm ../nginx/localhost.crt
cp localhost.key ~/.aspnet/https/localhost.key
cp localhost.crt ~/.aspnet/https/localhost.crt
cp localhost.pfx ~/.aspnet/https/localhost.pfx
cp localhost.key ../wallet-spa/localhost.key
cp localhost.crt ../wallet-spa/localhost.crt
cp localhost.key ../nginx/localhost.key
cp localhost.crt ../nginx/localhost.crt
mkdir https
openssl req -x509 -newkey rsa:2048 -keyout https/localhost.key -out https/localhost.crt -days 365 -nodes -config ssl-selfsigned.cnf
openssl pkcs12 -export -out https/localhost.pfx -inkey https/localhost.key -in https/localhost.crt -name "Localhost selfsigned certificate" -password pass:MyCertificatePassword
13 changes: 6 additions & 7 deletions .docker/startup-backend-only.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/bash
echo "1. Building Docker images in silent mode. This may take few minutes..."
echo -e "\n\n\tEnsure Docker is up and running.\n\n"
docker-compose build accounts-api
docker-compose build identity-server
docker-compose build --quiet
echo "2. Starting up SQL Server in Docker..."
docker-compose up -d sql1
echo "3. Installing Entity Framework Tool to migrate databases."
dotnet tool update --global dotnet-ef --version 3.1.7
echo "4. Generating accounts schema in DB..."
dotnet ef database update --project ../accounts-api/src/Infrastructure --startup-project ../accounts-api/src/WebApi
echo "5. Starting up Identity Server and Accounts applications."
echo "3. Updating DB using Entity Framework Tool..."
./init-db
echo -e "4. Starting up applications:"
echo -e "\tIdentity Server."
echo -e "\tAccounts."
docker-compose up -d identity-server
docker-compose up -d accounts-api
13 changes: 7 additions & 6 deletions .docker/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ echo -e "\n\n\tEnsure Docker is up and running.\n\n"
docker-compose build --quiet
echo "2. Starting up SQL Server in Docker..."
docker-compose up -d sql1
echo "3. Installing Entity Framework Tool to migrate databases."
dotnet tool update --global dotnet-ef --version 3.1.7
echo "4. Generating accounts schema in DB..."
dotnet ef database update --project ../accounts-api/src/Infrastructure --startup-project ../accounts-api/src/WebApi
echo "5. Starting up Identity Server and Accounts applications."
echo "3. Updating DB using Entity Framework Tool..."
./init-db
echo -e "4. Starting up applications:"
echo -e "\tIdentity Server."
echo -e "\tAccounts."
echo -e "\tSPA."
docker-compose up -d
echo -e "6. Browse to $(tput setaf 3)https://wallet.local/$(tput sgr0)\n\nUse the following credentials to login into Identity Server:\n\n\tUsername:\t$(tput setaf 3)alice$(tput sgr0)\n\tPassword:\t$(tput setaf 3)alice$(tput sgr0)"
echo -e "5. Browse to $(tput setaf 3)https://wallet.local/$(tput sgr0)\n\nUse the following credentials to login into Identity Server:\n\n\tUsername:\t$(tput setaf 3)alice$(tput sgr0)\n\tPassword:\t$(tput setaf 3)alice$(tput sgr0)"
2 changes: 1 addition & 1 deletion .docker/trustcert-mac.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
# https://gist.github.com/epcim/03f66dfa85ad56604c7b8e6df79614e0
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain localhost.crt
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain https/localhost.crt
4 changes: 4 additions & 0 deletions .docker/trustcert-windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# https://gist.github.com/epcim/03f66dfa85ad56604c7b8e6df79614e0
dotnet dev-certs https -ep https/localhost.pfx -p MyCertificatePassword
dotnet dev-certs https --trust
8 changes: 8 additions & 0 deletions Clean-Architecture-Manga.sln
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer", "identity-server\IdentityServer.csproj", "{01537DBF-3C0F-4B83-A089-0D12E5CA06C6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".docker", ".docker", "{FAA0BAC6-0AA8-4908-A287-D550E9F9CBA8}"
ProjectSection(SolutionItems) = preProject
.docker\makecert.sh = .docker\makecert.sh
.docker\ssl-selfsigned.cnf = .docker\ssl-selfsigned.cnf
.docker\startup-backend-only.sh = .docker\startup-backend-only.sh
.docker\startup.sh = .docker\startup.sh
.docker\trustcert-mac.sh = .docker\trustcert-mac.sh
.docker\trustcert-windows.sh = .docker\trustcert-windows.sh
EndProjectSection
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", ".docker\docker-compose.dcproj", "{A0517AF3-3B35-443A-80DC-FF94F10CF056}"
EndProject
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Startup the whole solution:
cd .docker
./makecert.sh
./trustcert-mac.sh
#./trustcert-windows.sh
./startup.sh
```

Expand All @@ -62,6 +63,7 @@ If you prefer dotnet commands then start each service individually:
```sh
dotnet dev-certs https --clean
dotnet dev-certs https -ep $env:USERPROFILE\.aspnet\https\aspnetapp.pfx -p MyCertificatePassword
dotnet dev-certs https --trust
```

### Spin up SQL Server in a Docker container
Expand Down
4 changes: 1 addition & 3 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
FROM nginx:latest

COPY nginx.conf /etc/nginx/nginx.conf
COPY localhost.crt /etc/ssl/certs/localhost.crt
COPY localhost.key /etc/ssl/private/localhost.key
COPY nginx.conf /etc/nginx/nginx.conf
24 changes: 0 additions & 24 deletions nginx/localhost.crt

This file was deleted.

28 changes: 0 additions & 28 deletions nginx/localhost.key

This file was deleted.

24 changes: 0 additions & 24 deletions wallet-spa/localhost.crt

This file was deleted.

28 changes: 0 additions & 28 deletions wallet-spa/localhost.key

This file was deleted.

0 comments on commit 2d889c6

Please sign in to comment.