Add gh actions to build #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Docker | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
workflow_dispatch: | |
env: | |
DOTNET_VERSION: '9.0.x' | |
DOCKER_REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: ${{ env.DOTNET_VERSION }} | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.DOCKER_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Restore dependencies | |
run: dotnet restore Safeturned.sln | |
- name: Build solution | |
run: dotnet build Safeturned.sln --configuration Release --no-restore | |
- name: Run tests | |
run: dotnet test Safeturned.sln --configuration Release --no-build --verbosity normal | |
- name: Install Aspire CLI | |
run: dotnet tool install -g Aspire.Cli | |
- name: Publish with Aspire | |
run: | | |
aspire publish --project-path Safeturned.AppHost/Safeturned.AppHost.csproj \ | |
--output-path ./publish/aspire | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./publish/aspire | |
file: ./publish/aspire/Dockerfile | |
push: true | |
tags: | | |
${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}/safeturned:${{ github.sha }} | |
${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}/safeturned:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Create Release | |
if: github.ref == 'refs/heads/main' | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ github.run_number }} | |
release_name: Release v${{ github.run_number }} | |
body: | | |
## Changes | |
- Built from commit: ${{ github.sha }} | |
- Docker image: `${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}/safeturned:${{ github.sha }}` | |
## Deployment | |
Run on your server with: | |
```bash | |
docker run -d \ | |
--name safeturned \ | |
-p 5000:80 \ | |
-e ASPNETCORE_ENVIRONMENT=Production \ | |
${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}/safeturned:latest | |
``` | |
draft: false | |
prerelease: false |