diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b629ca6..daf167f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,31 +31,31 @@ jobs: path: artifacts/*.nupkg retention-days: 2 - publish: - name: Publish - needs: build_test_pack - runs-on: windows-latest - env: - nugetSource: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json - DOTNET_NOLOGO: 1 - steps: - - name: Download artifacts - uses: actions/download-artifact@v2 - with: - name: packages - - name: Publish to Github Packages - run: dotnet nuget push *.nupkg --source $env:nugetSource --skip-duplicate --api-key ${{ secrets.GITHUB_TOKEN }} + # publish: + # name: Publish + # needs: build_test_pack + # runs-on: windows-latest + # env: + # nugetSource: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json + # DOTNET_NOLOGO: 1 + # steps: + # - name: Download artifacts + # uses: actions/download-artifact@v2 + # with: + # name: packages + # - name: Publish to Github Packages + # run: dotnet nuget push *.nupkg --source $env:nugetSource --skip-duplicate --api-key ${{ secrets.GITHUB_TOKEN }} - cleanup: - name: Cleanup - needs: build_test_pack - runs-on: ubuntu-latest - steps: - - name: Cleanup old Packages - uses: actions/delete-package-versions@v3 - with: - package-name: 'EPiServer.Templates' - min-versions-to-keep: 10 - # 1-in-1-out - num-old-versions-to-delete: 1 - delete-only-pre-release-versions: "true" + # cleanup: + # name: Cleanup + # needs: build_test_pack + # runs-on: ubuntu-latest + # steps: + # - name: Cleanup old Packages + # uses: actions/delete-package-versions@v3 + # with: + # package-name: 'EPiServer.Templates' + # min-versions-to-keep: 10 + # # 1-in-1-out + # num-old-versions-to-delete: 1 + # delete-only-pre-release-versions: "true" diff --git a/templates/Alloy.Mvc/.env b/templates/Alloy.Mvc/.env new file mode 100644 index 0000000..bb927b4 --- /dev/null +++ b/templates/Alloy.Mvc/.env @@ -0,0 +1,4 @@ +# These variables are used for passing values into docker-compose.yml and the containers +SA_PASSWORD=Qwerty12345! +DB_NAME=Alloy.Mvc.1 +DB_DIRECTORY=Alloy.Mvc.1 diff --git a/templates/Alloy.Mvc/.template.config/template.json b/templates/Alloy.Mvc/.template.config/template.json index e8dbda1..e58d721 100644 --- a/templates/Alloy.Mvc/.template.config/template.json +++ b/templates/Alloy.Mvc/.template.config/template.json @@ -19,7 +19,8 @@ "exclude": [ "Directory.Build.props", "docker-compose.yml", - "Docker/**/*" + "Docker/**/*", + ".env" ] } ] diff --git a/templates/Alloy.Mvc/Docker/create-db.sh b/templates/Alloy.Mvc/Docker/create-db.sh index c3f11cc..a32a7a3 100644 --- a/templates/Alloy.Mvc/Docker/create-db.sh +++ b/templates/Alloy.Mvc/Docker/create-db.sh @@ -1,8 +1,19 @@ #!/bin/bash +echo "Creating database..." + +let result=1 + for i in {1..100}; do - /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME}') CREATE DATABASE ${DB_NAME} ON (NAME=${DB_NAME}_data, FILENAME='/var/opt/mssql/host_data/${DB_NAME}.mdf') LOG ON (NAME=${DB_NAME}_log, FILENAME='/var/opt/mssql/host_data/${DB_NAME}.ldf')" - if [ $? -eq 0 ]; then + if test -f /var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.mdf; then + echo "Restoring from .mdf/.ldf" + /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME}') CREATE DATABASE ${DB_NAME} ON (NAME=${DB_NAME}_data, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.mdf') LOG ON (NAME=${DB_NAME}_log, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.ldf') FOR ATTACH;" + let result=$? + else + /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME}') CREATE DATABASE ${DB_NAME} ON (NAME=${DB_NAME}_data, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.mdf') LOG ON (NAME=${DB_NAME}_log, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.ldf')" + let result=$? + fi + if [ $result -eq 0 ]; then echo "Creating database completed" break else diff --git a/templates/Alloy.Mvc/README.md b/templates/Alloy.Mvc/README.md index fb363be..db4a370 100644 --- a/templates/Alloy.Mvc/README.md +++ b/templates/Alloy.Mvc/README.md @@ -21,6 +21,7 @@ $ dotnet run Prerequisities - Docker - Enable Docker support when applying the template +- Review the .env file and make changes where necessary to the Docker-related variables ```bash $ docker-compose up @@ -28,6 +29,12 @@ $ docker-compose up > Note that this Docker setup is just configured for local development. Follow this [guide to enable HTTPS](https://github.com/dotnet/dotnet-docker/blob/main/samples/run-aspnetcore-https-development.md). +#### Reclaiming Docker Image Space + +1. Backup the App_Data/\${DB_NAME}.mdf and App_Data/\${DB_NAME}.ldf DB restoration files for safety +2. Run `docker compose down --rmi all` to remove containers, networks, and images associated with the specific project instance +3. In the future, run `docker compose up` anytime you want to recreate the images and containers + ### Any OS with external database server Prerequisities diff --git a/templates/Alloy.Mvc/docker-compose.yml b/templates/Alloy.Mvc/docker-compose.yml index 8444742..8bdd2f9 100644 --- a/templates/Alloy.Mvc/docker-compose.yml +++ b/templates/Alloy.Mvc/docker-compose.yml @@ -6,12 +6,13 @@ services: dockerfile: ./Docker/db.dockerfile context: . environment: - SA_PASSWORD: Qwerty12345! - DB_NAME: cms + SA_PASSWORD: ${SA_PASSWORD} + DB_NAME: ${DB_NAME} + DB_DIRECTORY: ${DB_DIRECTORY} ports: - 6000:1433 volumes: - - ./App_Data:/var/opt/mssql/host_data + - ./App_Data:/var/opt/mssql/host_data/${DB_DIRECTORY} image: Alloy.Mvc.1/db web: depends_on: @@ -22,7 +23,7 @@ services: environment: ASPNETCORE_URLS: http://*:80 ASPNETCORE_ENVIRONMENT: Development - CONNECTIONSTRINGS__EPISERVERDB: Server=db;Database=cms;User Id=sa;Password=Qwerty12345!;Encrypt=False; + CONNECTIONSTRINGS__EPISERVERDB: Server=db;Database=${DB_NAME};User Id=sa;Password=${SA_PASSWORD};Encrypt=False; ports: - 5000:80 volumes: diff --git a/templates/Cms.Empty/.env b/templates/Cms.Empty/.env new file mode 100644 index 0000000..cf491ab --- /dev/null +++ b/templates/Cms.Empty/.env @@ -0,0 +1,4 @@ +# These variables are used for passing values into docker-compose.yml and the containers +SA_PASSWORD=Qwerty12345! +DB_NAME=Cms.Empty.1 +DB_DIRECTORY=Cms.Empty.1 diff --git a/templates/Cms.Empty/.template.config/template.json b/templates/Cms.Empty/.template.config/template.json index 50594f6..7fa80ca 100644 --- a/templates/Cms.Empty/.template.config/template.json +++ b/templates/Cms.Empty/.template.config/template.json @@ -19,7 +19,8 @@ "exclude": [ "Directory.Build.props", "docker-compose.yml", - "Docker/**/*" + "Docker/**/*", + ".env" ] } ] diff --git a/templates/Cms.Empty/Docker/create-db.sh b/templates/Cms.Empty/Docker/create-db.sh index c3f11cc..a32a7a3 100644 --- a/templates/Cms.Empty/Docker/create-db.sh +++ b/templates/Cms.Empty/Docker/create-db.sh @@ -1,8 +1,19 @@ #!/bin/bash +echo "Creating database..." + +let result=1 + for i in {1..100}; do - /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME}') CREATE DATABASE ${DB_NAME} ON (NAME=${DB_NAME}_data, FILENAME='/var/opt/mssql/host_data/${DB_NAME}.mdf') LOG ON (NAME=${DB_NAME}_log, FILENAME='/var/opt/mssql/host_data/${DB_NAME}.ldf')" - if [ $? -eq 0 ]; then + if test -f /var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.mdf; then + echo "Restoring from .mdf/.ldf" + /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME}') CREATE DATABASE ${DB_NAME} ON (NAME=${DB_NAME}_data, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.mdf') LOG ON (NAME=${DB_NAME}_log, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.ldf') FOR ATTACH;" + let result=$? + else + /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME}') CREATE DATABASE ${DB_NAME} ON (NAME=${DB_NAME}_data, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.mdf') LOG ON (NAME=${DB_NAME}_log, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.ldf')" + let result=$? + fi + if [ $result -eq 0 ]; then echo "Creating database completed" break else diff --git a/templates/Cms.Empty/README.md b/templates/Cms.Empty/README.md index 47a3282..f8b59de 100644 --- a/templates/Cms.Empty/README.md +++ b/templates/Cms.Empty/README.md @@ -19,6 +19,7 @@ $ dotnet run Prerequisities - Docker - Enable Docker support when applying the template +- Review the .env file and make changes where necessary to the Docker-related variables ```bash $ docker-compose up @@ -26,6 +27,12 @@ $ docker-compose up > Note that this Docker setup is just configured for local development. Follow this [guide to enable HTTPS](https://github.com/dotnet/dotnet-docker/blob/main/samples/run-aspnetcore-https-development.md). +#### Reclaiming Docker Image Space + +1. Backup the App_Data/\${DB_NAME}.mdf and App_Data/\${DB_NAME}.ldf DB restoration files for safety +2. Run `docker compose down --rmi all` to remove containers, networks, and images associated with the specific project instance +3. In the future, run `docker compose up` anytime you want to recreate the images and containers + ### Any OS with external database server Prerequisities diff --git a/templates/Cms.Empty/docker-compose.yml b/templates/Cms.Empty/docker-compose.yml index 2c46f81..544d432 100644 --- a/templates/Cms.Empty/docker-compose.yml +++ b/templates/Cms.Empty/docker-compose.yml @@ -6,12 +6,13 @@ services: dockerfile: ./Docker/db.dockerfile context: . environment: - SA_PASSWORD: Qwerty12345! - DB_NAME: cms + SA_PASSWORD: ${SA_PASSWORD} + DB_NAME: ${DB_NAME} + DB_DIRECTORY: ${DB_DIRECTORY} ports: - 6000:1433 volumes: - - ./App_Data:/var/opt/mssql/host_data + - ./App_Data:/var/opt/mssql/host_data/${DB_DIRECTORY} image: Cms.Empty.1/db web: depends_on: @@ -22,7 +23,7 @@ services: environment: ASPNETCORE_URLS: http://*:80 ASPNETCORE_ENVIRONMENT: Development - CONNECTIONSTRINGS__EPISERVERDB: Server=db;Database=cms;User Id=sa;Password=Qwerty12345!;Encrypt=False; + CONNECTIONSTRINGS__EPISERVERDB: Server=db;Database=${DB_NAME};User Id=sa;Password=${SA_PASSWORD};Encrypt=False; ports: - 5000:80 volumes: diff --git a/templates/Commerce.Empty/.env b/templates/Commerce.Empty/.env new file mode 100644 index 0000000..0d38a23 --- /dev/null +++ b/templates/Commerce.Empty/.env @@ -0,0 +1,5 @@ +# These variables are used for passing values into docker-compose.yml and the containers +SA_PASSWORD=Qwerty12345! +DB_NAME=Commerce.Empty.1_cms +DB_NAME_COMMERCE=Commerce.Empty.1_commerce +DB_DIRECTORY=Commerce.Empty.1 diff --git a/templates/Commerce.Empty/.template.config/template.json b/templates/Commerce.Empty/.template.config/template.json index 58e0a8b..ae3dc5f 100644 --- a/templates/Commerce.Empty/.template.config/template.json +++ b/templates/Commerce.Empty/.template.config/template.json @@ -19,7 +19,8 @@ "exclude": [ "Directory.Build.props", "docker-compose.yml", - "Docker/**/*" + "Docker/**/*", + ".env" ] } ] diff --git a/templates/Commerce.Empty/Docker/create-db.sh b/templates/Commerce.Empty/Docker/create-db.sh index 689b775..221411c 100644 --- a/templates/Commerce.Empty/Docker/create-db.sh +++ b/templates/Commerce.Empty/Docker/create-db.sh @@ -1,13 +1,35 @@ #!/bin/bash +echo "Creating databases..." + +let cmsresult=1 +let commerceresult=1 + for i in {1..100}; do - /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME}') CREATE DATABASE ${DB_NAME} ON (NAME=${DB_NAME}_data, FILENAME='/var/opt/mssql/host_data/${DB_NAME}.mdf') LOG ON (NAME=${DB_NAME}_log, FILENAME='/var/opt/mssql/host_data/${DB_NAME}.ldf')" - /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME_COMMERCE}') CREATE DATABASE ${DB_NAME_COMMERCE} ON (NAME=${DB_NAME_COMMERCE}_data, FILENAME='/var/opt/mssql/host_data/${DB_NAME_COMMERCE}.mdf') LOG ON (NAME=${DB_NAME_COMMERCE}_log, FILENAME='/var/opt/mssql/host_data/${DB_NAME_COMMERCE}.ldf')" - if [ $? -eq 0 ]; then - echo "Creating database completed" + if test -f /var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.mdf; then + echo "Restoring CMS DB from .mdf/.ldf" + + /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME}') CREATE DATABASE ${DB_NAME} ON (NAME=${DB_NAME}_data, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.mdf') LOG ON (NAME=${DB_NAME}_log, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.ldf') FOR ATTACH;" + let cmsresult=$? + else + /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME}') CREATE DATABASE ${DB_NAME} ON (NAME=${DB_NAME}_data, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.mdf') LOG ON (NAME=${DB_NAME}_log, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME}.ldf')" + let cmsresult=$? + fi + + if test -f /var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME_COMMERCE}.mdf; then + echo "Restoring Commerce DB from .mdf/.ldf" + /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME_COMMERCE}') CREATE DATABASE ${DB_NAME_COMMERCE} ON (NAME=${DB_NAME_COMMERCE}_data, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME_COMMERCE}.mdf') LOG ON (NAME=${DB_NAME_COMMERCE}_log, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME_COMMERCE}.ldf') FOR ATTACH;" + let commerceresult=$? + else + /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '${DB_NAME_COMMERCE}') CREATE DATABASE ${DB_NAME_COMMERCE} ON (NAME=${DB_NAME_COMMERCE}_data, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME_COMMERCE}.mdf') LOG ON (NAME=${DB_NAME_COMMERCE}_log, FILENAME='/var/opt/mssql/host_data/${DB_DIRECTORY}/${DB_NAME_COMMERCE}.ldf')" + let commerceresult=$? + fi + + if [ $cmsresult -eq 0 ] && [ $commerceresult -eq 0 ]; then + echo "Creating databases completed" break else - echo "Creating database. Not ready yet..." + echo "Creating databases. Not ready yet..." sleep 1 fi done \ No newline at end of file diff --git a/templates/Commerce.Empty/README.md b/templates/Commerce.Empty/README.md index 5cb7750..234b93a 100644 --- a/templates/Commerce.Empty/README.md +++ b/templates/Commerce.Empty/README.md @@ -19,6 +19,7 @@ $ dotnet run Prerequisities - Docker - Enable Docker support when applying the template +- Review the .env file and make changes where necessary to the Docker-related variables ```bash $ docker-compose up @@ -26,6 +27,12 @@ $ docker-compose up > Note that this Docker setup is just configured for local development. Follow this [guide to enable HTTPS](https://github.com/dotnet/dotnet-docker/blob/main/samples/run-aspnetcore-https-development.md). +#### Reclaiming Docker Image Space + +1. Backup the App_Data/\${DB_NAME}.mdf and App_Data/\${DB_NAME}.ldf DB restoration files for safety +2. Run `docker compose down --rmi all` to remove containers, networks, and images associated with the specific project instance +3. In the future, run `docker compose up` anytime you want to recreate the images and containers + ### Any OS with external database server Prerequisities diff --git a/templates/Commerce.Empty/docker-compose.yml b/templates/Commerce.Empty/docker-compose.yml index 3fa2f68..50cefeb 100644 --- a/templates/Commerce.Empty/docker-compose.yml +++ b/templates/Commerce.Empty/docker-compose.yml @@ -6,13 +6,14 @@ services: dockerfile: ./Docker/db.dockerfile context: . environment: - SA_PASSWORD: Qwerty12345! - DB_NAME: cms - DB_NAME_COMMERCE: commerce + SA_PASSWORD: ${SA_PASSWORD} + DB_NAME: ${DB_NAME} + DB_NAME_COMMERCE: ${DB_NAME_COMMERCE} + DB_DIRECTORY: ${DB_DIRECTORY} ports: - 6000:1433 volumes: - - ./App_Data:/var/opt/mssql/host_data + - ./App_Data:/var/opt/mssql/host_data/${DB_DIRECTORY} image: Commerce.Empty.1/db web: depends_on: @@ -23,8 +24,8 @@ services: environment: ASPNETCORE_URLS: http://*:80 ASPNETCORE_ENVIRONMENT: Development - CONNECTIONSTRINGS__EPISERVERDB: Server=db;Database=cms;User Id=sa;Password=Qwerty12345!;Encrypt=False; - CONNECTIONSTRINGS__ECFSQLCONNECTION: Server=db;Database=commerce;User Id=sa;Password=Qwerty12345!;Encrypt=False; + CONNECTIONSTRINGS__EPISERVERDB: Server=db;Database=${DB_NAME};User Id=sa;Password=${SA_PASSWORD};Encrypt=False; + CONNECTIONSTRINGS__ECFSQLCONNECTION: Server=db;Database=${DB_NAME_COMMERCE};User Id=sa;Password=${SA_PASSWORD};Encrypt=False; ports: - 5000:80 volumes: