Skip to content

Commit 53eb33a

Browse files
committed
Migrate to .NET 8 project structure + deployment scripts
1 parent 55f04b9 commit 53eb33a

183 files changed

Lines changed: 276 additions & 431 deletions

File tree

Some content is hidden

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

.deploy/docker-compose-template.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.deploy/docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
WS_HOST: ws://${HOST_DOMAIN}
11+
WS_PORT: 80
12+
VIRTUAL_HOST: ${HOST_DOMAIN}
13+
VIRTUAL_PORT: 8080 # New default ASP.NET port -> https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/aspnet-port
14+
LETSENCRYPT_HOST: ${HOST_DOMAIN}
15+
LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}
16+
LC_ALL: "en_US.UTF-8"
17+
LANG: "en_US.UTF-8"
18+
volumes:
19+
- app-mydb:/app/App_Data
20+
21+
networks:
22+
default:
23+
external: true
24+
name: nginx
25+
26+
volumes:
27+
app-mydb:

.deploy/nginx-proxy-compose.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
version: '2'
1+
version: "3.9"
22

33
services:
44
nginx-proxy:
5-
image: jwilder/nginx-proxy
5+
image: nginxproxy/nginx-proxy
66
container_name: nginx-proxy
77
restart: always
88
ports:
@@ -15,26 +15,32 @@ services:
1515
- dhparam:/etc/nginx/dhparam
1616
- certs:/etc/nginx/certs:ro
1717
- /var/run/docker.sock:/tmp/docker.sock:ro
18-
network_mode: bridge
18+
labels:
19+
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"
1920

2021
letsencrypt:
21-
image: jrcs/letsencrypt-nginx-proxy-companion:2.0
22+
image: nginxproxy/acme-companion:2.2
2223
container_name: nginx-proxy-le
2324
restart: always
25+
depends_on:
26+
- "nginx-proxy"
2427
environment:
2528
- DEFAULT_EMAIL=you@example.com
26-
volumes_from:
27-
- nginx-proxy
2829
volumes:
2930
- certs:/etc/nginx/certs:rw
3031
- acme:/etc/acme.sh
32+
- vhost:/etc/nginx/vhost.d
33+
- html:/usr/share/nginx/html
3134
- /var/run/docker.sock:/var/run/docker.sock:ro
32-
network_mode: bridge
35+
36+
networks:
37+
default:
38+
name: nginx
3339

3440
volumes:
3541
conf:
3642
vhost:
3743
html:
3844
dhparam:
3945
certs:
40-
acme:
46+
acme:

.github/workflows/README.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,13 @@ jobs:
1111
runs-on: ubuntu-22.04
1212
steps:
1313
- name: checkout
14-
uses: actions/checkout@v2.0.0
14+
uses: actions/checkout@v3
1515

16-
- name: setup .net core
17-
uses: actions/setup-dotnet@v1.7.2
16+
- name: Setup dotnet
17+
uses: actions/setup-dotnet@v3
1818
with:
19-
dotnet-version: 6.0.x
19+
dotnet-version: '8.0'
2020

2121
- name: build
2222
run: dotnet build
23-
working-directory: ./src
24-
25-
- name: test
26-
run: |
27-
dotnet test
28-
if [ $? -eq 0 ]; then
29-
echo TESTS PASSED
30-
else
31-
echo TESTS FAILED
32-
exit 1
33-
fi
34-
working-directory: ./src/Test.Tests
35-
23+
working-directory: ./

.github/workflows/release.yml

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,21 @@ on:
2222

2323
jobs:
2424
push_to_registry:
25-
runs-on: ubuntu-20.04
25+
runs-on: ubuntu-22.04
2626
if: ${{ github.event.workflow_run.conclusion != 'failure' }}
2727
steps:
2828
# Checkout latest or specific tag
2929
- name: checkout
3030
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
31-
uses: actions/checkout@v2
31+
uses: actions/checkout@v3
3232
- name: checkout tag
3333
if: ${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }}
34-
uses: actions/checkout@v2
34+
uses: actions/checkout@v3
3535
with:
3636
ref: refs/tags/${{ github.event.inputs.version }}
37-
38-
- name: Setup dotnet
39-
uses: actions/setup-dotnet@v1
40-
with:
41-
dotnet-version: '6.0'
42-
37+
4338
# Assign environment variables used in subsequent steps
44-
- name: repository name fix
39+
- name: Env variable assignment
4540
run: echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
4641
# TAG_NAME defaults to 'latest' if not a release or manual deployment
4742
- name: Assign version
@@ -54,39 +49,33 @@ jobs:
5449
echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
5550
fi;
5651
57-
# Authenticate, build and push to GitHub Container Registry (ghcr.io)
5852
- name: Login to GitHub Container Registry
59-
uses: docker/login-action@v1
53+
uses: docker/login-action@v2
6054
with:
6155
registry: ghcr.io
62-
username: ${{ github.repository_owner }}
56+
username: ${{ github.actor }}
6357
password: ${{ secrets.GITHUB_TOKEN }}
64-
58+
6559
# Build and push new docker image, skip for manual redeploy other than 'latest'
66-
- name: Build and push Docker images
67-
uses: docker/build-push-action@v2.2.2
68-
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
69-
with:
70-
file: ./src/Dockerfile
71-
context: ./src
72-
push: true
73-
tags: ghcr.io/${{ env.image_repository_name }}:${{ env.TAG_NAME }}
74-
60+
- name: Build and push Docker image
61+
run: |
62+
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
63+
7564
deploy_via_ssh:
7665
needs: push_to_registry
77-
runs-on: ubuntu-20.04
66+
runs-on: ubuntu-22.04
7867
if: ${{ github.event.workflow_run.conclusion != 'failure' }}
7968
steps:
69+
# Checkout latest or specific tag
8070
- name: checkout
8171
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
82-
uses: actions/checkout@v2
72+
uses: actions/checkout@v3
8373
- name: checkout tag
8474
if: ${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }}
85-
uses: actions/checkout@v2
75+
uses: actions/checkout@v3
8676
with:
8777
ref: refs/tags/${{ github.event.inputs.version }}
8878

89-
# Assign environment variables used in subsequent steps
9079
- name: repository name fix and env
9180
run: |
9281
echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
@@ -97,56 +86,46 @@ jobs:
9786
if [ "${{ github.event.inputs.version }}" != "" ]; then
9887
echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
9988
fi;
100-
- name: docker-compose file prep
101-
uses: danielr1996/envsubst-action@1.0.0
102-
env:
103-
RELEASE_VERSION: ${{ env.TAG_NAME }}
104-
IMAGE_REPO: ${{ env.image_repository_name }}
105-
APP_NAME: ${{ github.event.repository.name }}
106-
HOST_DOMAIN: ${{ secrets.DEPLOY_API }}
107-
LETSENCRYPT_EMAIL: ${{ secrets.LETSENCRYPT_EMAIL }}
108-
with:
109-
input: .deploy/docker-compose-template.yml
110-
output: .deploy/${{ github.event.repository.name }}-docker-compose.yml
11189
112-
- name: copy compose file via scp
90+
- name: Create .env file
91+
run: |
92+
echo "Generating .env file"
93+
94+
echo "# Autogenerated .env file" > .deploy/.env
95+
echo "HOST_DOMAIN=${{ secrets.DEPLOY_HOST }}" >> .deploy/.env
96+
echo "LETSENCRYPT_EMAIL=${{ secrets.LETSENCRYPT_EMAIL }}" >> .deploy/.env
97+
echo "APP_NAME=${{ github.event.repository.name }}" >> .deploy/.env
98+
echo "IMAGE_REPO=${{ env.image_repository_name }}" >> .deploy/.env
99+
echo "RELEASE_VERSION=${{ env.TAG_NAME }}" >> .deploy/.env
100+
101+
# Copy only the docker-compose.yml to remote server home folder
102+
- name: copy files to target server via scp
113103
uses: appleboy/scp-action@v0.1.3
114104
with:
115-
host: ${{ secrets.DEPLOY_API }}
105+
host: ${{ secrets.DEPLOY_HOST }}
116106
username: ${{ secrets.DEPLOY_USERNAME }}
117107
port: 22
118108
key: ${{ secrets.DEPLOY_KEY }}
119-
source: ".deploy/${{ github.event.repository.name }}-docker-compose.yml"
120-
target: "~/"
121-
122-
- name: Run remote db migrations
123-
uses: appleboy/ssh-action@v0.1.4
124-
env:
125-
APPTOKEN: ${{ secrets.GITHUB_TOKEN }}
126-
USERNAME: ${{ secrets.DEPLOY_USERNAME }}
127-
with:
128-
host: ${{ secrets.DEPLOY_API }}
129-
username: ${{ secrets.DEPLOY_USERNAME }}
130-
key: ${{ secrets.DEPLOY_KEY }}
131-
port: 22
132-
envs: APPTOKEN,USERNAME
133-
script: |
134-
echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin
135-
docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml pull
136-
docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml up ${{ github.event.repository.name }}-migration
109+
strip_components: 2
110+
source: "./.deploy/docker-compose.yml,./.deploy/.env"
111+
target: "~/.deploy/${{ github.event.repository.name }}/"
137112

113+
# Deploy Docker image with your application using `docker compose up` remotely
138114
- name: remote docker-compose up via ssh
139-
uses: appleboy/ssh-action@v0.1.4
115+
uses: appleboy/ssh-action@v0.1.5
140116
env:
141117
APPTOKEN: ${{ secrets.GITHUB_TOKEN }}
142118
USERNAME: ${{ secrets.DEPLOY_USERNAME }}
143119
with:
144-
host: ${{ secrets.DEPLOY_API }}
120+
host: ${{ secrets.DEPLOY_HOST }}
145121
username: ${{ secrets.DEPLOY_USERNAME }}
146122
key: ${{ secrets.DEPLOY_KEY }}
147-
port: ${{ secrets.DEPLOY_PORT }}
123+
port: 22
148124
envs: APPTOKEN,USERNAME
149125
script: |
150126
echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin
151-
docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml pull
152-
docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml up -d
127+
cd ~/.deploy/${{ github.event.repository.name }}
128+
docker compose pull
129+
export APP_ID=$(docker compose run --entrypoint "id -u" --rm app)
130+
docker compose run --entrypoint "chown $APP_ID:$APP_ID /app/App_Data" --user root --rm app
131+
docker compose up app -d
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)