Skip to content

Commit b5cafbc

Browse files
committed
Upgrade to v8 + .net8
1 parent cfaad6f commit b5cafbc

10 files changed

Lines changed: 202 additions & 121 deletions

File tree

.deploy/docker-compose-template.yml

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

.deploy/docker-compose.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
networks:
18+
default:
19+
external: true
20+
name: nginx
21+
22+
volumes:
23+
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: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,99 @@
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-
41
## Overview
5-
A docker image is built and stored on GitHub's `ghcr.io` docker registry when a GitHub Release is created.
62

7-
GitHub Actions specified in `release.yml` then copy files remotely via scp and use `docker-compose` to run the app remotely via SSH.
3+
This template uses the deployment configurations for a ServiceStack .NET 8 application. The application is containerized using Docker and is set up to be automatically built and deployed via GitHub Actions. The recommended deployment target is a stand-alone Linux server running Ubuntu, with an NGINX reverse proxy also containerized using Docker, which a Docker Compose file is included in the template under the `.deploy` directory.
4+
5+
### Highlights
6+
- 🌐 **NGINX Reverse Proxy**: Utilizes an NGINX reverse proxy to handle web traffic and SSL termination.
7+
- 🚀 **GitHub Actions**: Leverages GitHub Actions for CI/CD, pushing Docker images to GitHub Container Registry and deploying them on a remote server.
8+
- 🐳 **Dockerized ServiceStack App**: The application is containerized, with the image built using `.NET 8`.
9+
- 🔄 **Automated Migrations**: Includes a separate service for running database migrations.
10+
11+
### Technology Stack
12+
- **Web Framework**: ServiceStack
13+
- **Language**: C# (.NET 8)
14+
- **Containerization**: Docker
15+
- **Reverse Proxy**: NGINX
16+
- **CI/CD**: GitHub Actions
17+
- **OS**: Ubuntu 22.04 (Deployment Server)
18+
19+
20+
21+
## Deployment Server Setup
22+
23+
To successfully host your ServiceStack applications, there are several components you need to set up on your deployment server. This guide assumes you're working on a standalone Linux server (Ubuntu is recommended) with SSH access enabled.
824

9-
## Deployment server setup
10-
To get this working, a server needs to be setup with the following:
25+
### Prerequisites
1126

12-
- SSH access
13-
- docker
14-
- docker-compose
15-
- ports 443 and 80 for web access of your hosted application
27+
1. **SSH Access**: Required for GitHub Actions to communicate with your server.
28+
2. **Docker**: To containerize your application.
29+
3. **Docker-Compose**: For orchestrating multiple containers.
30+
4. **Ports**: 80 and 443 should be open for web access.
31+
5. **nginx-reverse-proxy**: For routing traffic to multiple ServiceStack applications and managing TLS certificates.
1632

17-
This can be your own server or any cloud hosted server like Digital Ocean, AWS, Azure etc.
33+
You can use any cloud-hosted or on-premises server like Digital Ocean, AWS, Azure, etc., for this setup.
1834

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.
35+
### Step-by-Step Guide
2036

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.
37+
#### 1. Install Docker and Docker-Compose
2238

23-
For example, once copied to remote `~/nginx-proxy-compose.yml`, the following command can be run on the remote server.
39+
It is best to follow the [latest installation instructions on the Docker website](https://docs.docker.com/engine/install/ubuntu/) to ensure to have the correct setup with the latest patches.
2440

41+
#### 2. Configure SSH for GitHub Actions
42+
43+
Generate a dedicated SSH key pair to be used by GitHub Actions:
44+
45+
```bash
46+
ssh-keygen -t rsa -b 4096 -f ~/.ssh/github_actions
2547
```
26-
docker-compose -f ~/nginx-proxy-compose.yml up -d
48+
49+
Add the public key to the `authorized_keys` file on your server:
50+
51+
```bash
52+
cat ~/.ssh/github_actions.pub >> ~/.ssh/authorized_keys
2753
```
2854

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.
55+
Then, add the *private* key to your GitHub Secrets as `DEPLOY_KEY` to enable GitHub Actions to SSH into the server securely.
3056

31-
## GitHub Repository setup
32-
The `release.yml` uses the following secrets.
57+
#### 3. Set Up nginx-reverse-proxy
3358

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_PORT - SSH port, usually `22`.
36-
- DEPLOY_USERNAME - the username being logged into via SSH. Eg, `ubuntu`, `ec2-user`, `root` etc.
37-
- DEPLOY_KEY - SSH private key used to remotely access deploy server/app host.
38-
- LETSENCRYPT_EMAIL - Email address, required for Let's Encrypt automated TLS certificates.
59+
You should have a `docker-compose` file similar to the `nginx-proxy-compose.yml` in your repository. Upload this file to your server:
3960

40-
These secrets can use the [GitHub CLI](https://cli.github.com/manual/gh_secret_set) for ease of creation.
61+
```bash
62+
scp nginx-proxy-compose.yml user@your_server:~/
63+
```
4164

42-
These secrets are used to populate variables within GitHub Actions and other configuration files.
65+
To bring up the nginx reverse proxy and its companion container for handling TLS certificates, run:
4366

44-
## What's the process of `release.yml`?
67+
```bash
68+
docker compose -f ~/nginx-proxy-compose.yml up -d
69+
```
70+
71+
This will start an nginx reverse proxy along with a companion container. They will automatically watch for additional Docker containers on the same network and initialize them with valid TLS certificates.
72+
73+
74+
75+
## GitHub Repository Setup
76+
77+
Configuring your GitHub repository is an essential step for automating deployments via GitHub Actions. This guide assumes you have a `release.yml` workflow file in your repository's `.github/workflows/` directory, and your deployment server has been set up according to the [Deployment Server Setup](#Deployment-Server-Setup) guidelines.
78+
79+
### Secrets Configuration
80+
81+
Your GitHub Actions workflow requires the following secrets to be set in your GitHub repository:
82+
83+
1. **`DEPLOY_HOST`**: The hostname for SSH access. This can be either an IP address or a domain with an A-record pointing to your server.
84+
2. **`DEPLOY_USERNAME`**: The username for SSH login. Common examples include `ubuntu`, `ec2-user`, or `root`.
85+
3. **`DEPLOY_KEY`**: The SSH private key to securely access the deployment server. This should be the same key you've set up on your server for GitHub Actions.
86+
4. **`LETSENCRYPT_EMAIL`**: Your email address, required for Let's Encrypt automated TLS certificates.
87+
88+
#### Using GitHub CLI for Secret Management
89+
90+
You can conveniently set these secrets using the [GitHub CLI](https://cli.github.com/manual/gh_secret_set) like this:
91+
92+
```bash
93+
gh secret set DEPLOY_HOST --body="your-host-or-ip"
94+
gh secret set DEPLOY_USERNAME --body="your-username"
95+
gh secret set DEPLOY_KEY --bodyFile="path/to/your/ssh-private-key"
96+
gh secret set LETSENCRYPT_EMAIL --body="your-email@example.com"
97+
```
4598

46-
![](https://raw.githubusercontent.com/ServiceStack/docs/master/docs/images/mix/release-ghr-vanilla-diagram.png)
99+
These secrets will populate environment variables within your GitHub Actions workflow and other configuration files, enabling secure and automated deployment of your ServiceStack applications.

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-20.04
11+
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.100
19+
dotnet-version: '8.0'
2020

2121
- name: build
2222
run: dotnet build
@@ -31,5 +31,5 @@ jobs:
3131
echo TESTS FAILED
3232
exit 1
3333
fi
34-
working-directory: ./ExampleDataApis.Tests
34+
working-directory: ./MyApp.Tests
3535

0 commit comments

Comments
 (0)