Skip to content

Commit c62b743

Browse files
committed
Add initial Blazor Vue Diffusion App
0 parents  commit c62b743

File tree

264 files changed

+60628
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

264 files changed

+60628
-0
lines changed

.deploy/docker-compose.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: "3.9"
2+
services:
3+
app:
4+
image: ghcr.io/${IMAGE_REPO}:${RELEASE_VERSION}
5+
restart: always
6+
ports:
7+
- "8080"
8+
container_name: ${APP_NAME}_app
9+
environment:
10+
VIRTUAL_HOST: ${HOST_DOMAIN}
11+
VIRTUAL_PORT: 8080 # New default ASP.NET port -> https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/aspnet-port
12+
LETSENCRYPT_HOST: ${HOST_DOMAIN}
13+
LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}
14+
volumes:
15+
- app-mydb:/app/App_Data
16+
17+
app-migration:
18+
image: ghcr.io/${IMAGE_REPO}:${RELEASE_VERSION}
19+
restart: "no"
20+
container_name: ${APP_NAME}_app_migration
21+
profiles:
22+
- migration
23+
command: --AppTasks=migrate
24+
volumes:
25+
- app-mydb:/app/App_Data
26+
27+
networks:
28+
default:
29+
external: true
30+
name: nginx
31+
32+
volumes:
33+
app-mydb:

.deploy/nginx-proxy-compose.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: "3.9"
2+
3+
services:
4+
nginx-proxy:
5+
image: nginxproxy/nginx-proxy
6+
container_name: nginx-proxy
7+
restart: always
8+
ports:
9+
- "80:80"
10+
- "443:443"
11+
volumes:
12+
- conf:/etc/nginx/conf.d
13+
- vhost:/etc/nginx/vhost.d
14+
- html:/usr/share/nginx/html
15+
- dhparam:/etc/nginx/dhparam
16+
- certs:/etc/nginx/certs:ro
17+
- /var/run/docker.sock:/tmp/docker.sock:ro
18+
labels:
19+
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"
20+
21+
letsencrypt:
22+
image: nginxproxy/acme-companion:2.2
23+
container_name: nginx-proxy-le
24+
restart: always
25+
depends_on:
26+
- "nginx-proxy"
27+
environment:
28+
29+
volumes:
30+
- certs:/etc/nginx/certs:rw
31+
- acme:/etc/acme.sh
32+
- vhost:/etc/nginx/vhost.d
33+
- html:/usr/share/nginx/html
34+
- /var/run/docker.sock:/var/run/docker.sock:ro
35+
36+
networks:
37+
default:
38+
name: nginx
39+
40+
volumes:
41+
conf:
42+
vhost:
43+
html:
44+
dhparam:
45+
certs:
46+
acme:

.github/workflows/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ServiceStack mix GitHub Actions
2+
The `release.yml` in designed to help with CI deployment to a dedicated server with SSH access, Docker and Docker Compose.
3+
4+
## Overview
5+
A docker image is built and stored on GitHub's `ghcr.io` docker registry when a GitHub Release is created.
6+
7+
GitHub Actions specified in `release.yml` then copy files remotely via scp and use `docker-compose` to run the app remotely via SSH.
8+
9+
## Deployment server setup
10+
To get this working, a server needs to be setup with the following:
11+
12+
- SSH access
13+
- docker
14+
- docker-compose
15+
- ports 443 and 80 for web access of your hosted application
16+
17+
This can be your own server or any cloud hosted server like Digital Ocean, AWS, Azure etc.
18+
19+
When setting up your server, you'll want to use a dedicated SSH key for access to be used by GitHub Actions. GitHub Actions will need the *private* SSH key within a GitHub Secret to authenticate. This can be done via ssh-keygen and copying the public key to the authorized clients on the server.
20+
21+
To let your server handle multiple ServiceStack applications and automate the generation and management of TLS certificates, an additional docker-compose file is provided via the `x mix` template, `nginx-proxy-compose.yml`. This docker-compose file is ready to run and can be copied to the deployment server.
22+
23+
For example, once copied to remote `~/nginx-proxy-compose.yml`, the following command can be run on the remote server.
24+
25+
```
26+
docker-compose -f ~/nginx-proxy-compose.yml up -d
27+
```
28+
29+
This will run an nginx reverse proxy along with a companion container that will watch for additional containers in the same docker network and attempt to initialize them with valid TLS certificates.
30+
31+
## GitHub Repository setup
32+
The `release.yml` uses the following secrets.
33+
34+
- DEPLOY_HOST - hostname used to SSH to, this can either be an IP address or subdomain with A record pointing to the server.
35+
- DEPLOY_USERNAME - the username being logged into via SSH. Eg, `ubuntu`, `ec2-user`, `root` etc.
36+
- DEPLOY_KEY - SSH private key used to remotely access deploy server/app host.
37+
- LETSENCRYPT_EMAIL - Email address, required for Let's Encrypt automated TLS certificates.
38+
39+
These secrets can use the [GitHub CLI](https://cli.github.com/manual/gh_secret_set) for ease of creation.
40+
41+
These secrets are used to populate variables within GitHub Actions and other configuration files.
42+
43+
## What's the process of `release.yml`?
44+
45+
![](https://raw.githubusercontent.com/ServiceStack/docs/master/docs/images/mix/release-ghr-vanilla-diagram.png)

.github/workflows/build.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build
2+
3+
on:
4+
pull_request: {}
5+
push:
6+
branches:
7+
- '**' # matches every branch
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-22.04
12+
steps:
13+
- name: checkout
14+
uses: actions/checkout@v3
15+
16+
- name: setup .net core
17+
uses: actions/setup-dotnet@v3
18+
with:
19+
dotnet-version: '8.*'
20+
dotnet-quality: 'preview'
21+
22+
- name: build
23+
run: dotnet build
24+
working-directory: .
25+
26+
- name: test
27+
run: |
28+
dotnet test
29+
if [ $? -eq 0 ]; then
30+
echo TESTS PASSED
31+
else
32+
echo TESTS FAILED
33+
exit 1
34+
fi
35+
working-directory: ./BlazorDiffusion.Tests
36+

.github/workflows/release.yml

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: Release
2+
permissions:
3+
packages: write
4+
contents: write
5+
on:
6+
# Triggered on new GitHub Release
7+
release:
8+
types: [published]
9+
# Triggered on every successful Build action
10+
workflow_run:
11+
workflows: ["Build"]
12+
branches: [main,master]
13+
types:
14+
- completed
15+
# Manual trigger for rollback to specific release or redeploy latest
16+
workflow_dispatch:
17+
inputs:
18+
version:
19+
default: latest
20+
description: Tag you want to release.
21+
required: true
22+
23+
jobs:
24+
push_to_registry:
25+
runs-on: ubuntu-22.04
26+
if: ${{ github.event.workflow_run.conclusion != 'failure' }}
27+
steps:
28+
# Checkout latest or specific tag
29+
- name: checkout
30+
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
31+
uses: actions/checkout@v3
32+
- name: checkout tag
33+
if: ${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }}
34+
uses: actions/checkout@v3
35+
with:
36+
ref: refs/tags/${{ github.event.inputs.version }}
37+
38+
# Assign environment variables used in subsequent steps
39+
- name: Env variable assignment
40+
run: echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
41+
# TAG_NAME defaults to 'latest' if not a release or manual deployment
42+
- name: Assign version
43+
run: |
44+
echo "TAG_NAME=latest" >> $GITHUB_ENV
45+
if [ "${{ github.event.release.tag_name }}" != "" ]; then
46+
echo "TAG_NAME=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
47+
fi;
48+
if [ "${{ github.event.inputs.version }}" != "" ]; then
49+
echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
50+
fi;
51+
52+
- name: Login to GitHub Container Registry
53+
uses: docker/login-action@v2
54+
with:
55+
registry: ghcr.io
56+
username: ${{ github.actor }}
57+
password: ${{ secrets.GITHUB_TOKEN }}
58+
59+
60+
- name: setup .net core
61+
uses: actions/setup-dotnet@v3
62+
with:
63+
dotnet-version: '8.*'
64+
dotnet-quality: 'preview'
65+
66+
# Build and push new docker image, skip for manual redeploy other than 'latest'
67+
- name: Build and push Docker image
68+
run: |
69+
dotnet publish --os linux --arch x64 -c Release -p:ContainerRepository=${{ env.image_repository_name }} -p:ContainerRegistry=ghcr.io -p:ContainerImageTags=${{ env.TAG_NAME }} -p:ContainerPort=80
70+
71+
deploy_via_ssh:
72+
needs: push_to_registry
73+
runs-on: ubuntu-22.04
74+
if: ${{ github.event.workflow_run.conclusion != 'failure' }}
75+
steps:
76+
# Checkout latest or specific tag
77+
- name: checkout
78+
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
79+
uses: actions/checkout@v3
80+
- name: checkout tag
81+
if: ${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }}
82+
uses: actions/checkout@v3
83+
with:
84+
ref: refs/tags/${{ github.event.inputs.version }}
85+
86+
- name: repository name fix and env
87+
run: |
88+
echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
89+
echo "TAG_NAME=latest" >> $GITHUB_ENV
90+
if [ "${{ github.event.release.tag_name }}" != "" ]; then
91+
echo "TAG_NAME=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
92+
fi;
93+
if [ "${{ github.event.inputs.version }}" != "" ]; then
94+
echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
95+
fi;
96+
97+
- name: Create .env file
98+
run: |
99+
echo "Generating .env file"
100+
101+
echo "# Autogenerated .env file" > .deploy/.env
102+
echo "HOST_DOMAIN=${{ secrets.DEPLOY_HOST }}" >> .deploy/.env
103+
echo "LETSENCRYPT_EMAIL=${{ secrets.LETSENCRYPT_EMAIL }}" >> .deploy/.env
104+
echo "APP_NAME=${{ github.event.repository.name }}" >> .deploy/.env
105+
echo "IMAGE_REPO=${{ env.image_repository_name }}" >> .deploy/.env
106+
echo "RELEASE_VERSION=${{ env.TAG_NAME }}" >> .deploy/.env
107+
108+
# Copy only the docker-compose.yml to remote server home folder
109+
- name: copy files to target server via scp
110+
uses: appleboy/[email protected]
111+
with:
112+
host: ${{ secrets.DEPLOY_HOST }}
113+
username: ${{ secrets.DEPLOY_USERNAME }}
114+
port: 22
115+
key: ${{ secrets.DEPLOY_KEY }}
116+
strip_components: 2
117+
source: "./.deploy/docker-compose.yml,./.deploy/.env"
118+
target: "~/.deploy/${{ github.event.repository.name }}/"
119+
120+
- name: Run remote db migrations
121+
uses: appleboy/[email protected]
122+
env:
123+
APPTOKEN: ${{ secrets.GITHUB_TOKEN }}
124+
USERNAME: ${{ secrets.DEPLOY_USERNAME }}
125+
with:
126+
host: ${{ secrets.DEPLOY_HOST }}
127+
username: ${{ secrets.DEPLOY_USERNAME }}
128+
key: ${{ secrets.DEPLOY_KEY }}
129+
port: 22
130+
envs: APPTOKEN,USERNAME
131+
script: |
132+
set -e
133+
echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin
134+
cd ~/.deploy/${{ github.event.repository.name }}
135+
docker compose pull
136+
export APP_ID=$(docker compose run --entrypoint "id -u" --rm app)
137+
docker compose run --entrypoint "chown $APP_ID:$APP_ID /app/App_Data" --user root --rm app
138+
docker compose up app-migration --exit-code-from app-migration
139+
140+
# Deploy Docker image with your application using `docker compose up` remotely
141+
- name: remote docker-compose up via ssh
142+
uses: appleboy/[email protected]
143+
env:
144+
APPTOKEN: ${{ secrets.GITHUB_TOKEN }}
145+
USERNAME: ${{ secrets.DEPLOY_USERNAME }}
146+
with:
147+
host: ${{ secrets.DEPLOY_HOST }}
148+
username: ${{ secrets.DEPLOY_USERNAME }}
149+
key: ${{ secrets.DEPLOY_KEY }}
150+
port: 22
151+
envs: APPTOKEN,USERNAME
152+
script: |
153+
echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin
154+
cd ~/.deploy/${{ github.event.repository.name }}
155+
docker compose pull
156+
docker compose up app -d

0 commit comments

Comments
 (0)