Skip to content

Commit

Permalink
upgrade to latest build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jan 16, 2024
1 parent a0d77b5 commit 8b8e208
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 92 deletions.
17 changes: 0 additions & 17 deletions .deploy/docker-compose-template.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "3.9"
services:
app:
image: ghcr.io/${IMAGE_REPO}:${RELEASE_VERSION}
restart: always
# network_mode: bridge
ports:
- "8080"
container_name: ${APP_NAME}_app
environment:
WS_HOST: ws://${HOST_DOMAIN}
WS_PORT: 80
VIRTUAL_HOST: ${HOST_DOMAIN}
VIRTUAL_PORT: 8080 # New default ASP.NET port -> https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/aspnet-port
LETSENCRYPT_HOST: ${HOST_DOMAIN}
LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}
LC_ALL: "en_US.UTF-8"
LANG: "en_US.UTF-8"
volumes:
- app-mydb:/app/App_Data

networks:
default:
external: true
name: nginx

volumes:
app-mydb:
22 changes: 14 additions & 8 deletions .deploy/nginx-proxy-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: '2'
version: "3.9"

services:
nginx-proxy:
image: jwilder/nginx-proxy
image: nginxproxy/nginx-proxy
container_name: nginx-proxy
restart: always
ports:
Expand All @@ -15,26 +15,32 @@ services:
- dhparam:/etc/nginx/dhparam
- certs:/etc/nginx/certs:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
network_mode: bridge
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"

letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion:2.0
image: nginxproxy/acme-companion:2.2
container_name: nginx-proxy-le
restart: always
depends_on:
- "nginx-proxy"
environment:
- [email protected]
volumes_from:
- nginx-proxy
volumes:
- certs:/etc/nginx/certs:rw
- acme:/etc/acme.sh
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- /var/run/docker.sock:/var/run/docker.sock:ro
network_mode: bridge

networks:
default:
name: nginx

volumes:
conf:
vhost:
html:
dhparam:
certs:
acme:
acme:
100 changes: 34 additions & 66 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,15 @@ jobs:
# Checkout latest or specific tag
- name: checkout
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: checkout tag
if: ${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }}
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: refs/tags/${{ github.event.inputs.version }}

- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0'


# Assign environment variables used in subsequent steps
- name: repository name fix
- name: Env variable assignment
run: echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
# TAG_NAME defaults to 'latest' if not a release or manual deployment
- name: Assign version
Expand All @@ -54,59 +49,33 @@ jobs:
echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
fi;
- name: Run CI Prebuild Script
env:
deploy_api: ${{ secrets.DEPLOY_API }}
run: |
if [ -e ./.deploy/ci.prebuild.sh ]
then
chmod +x ./.deploy/ci.prebuild.sh
./.deploy/ci.prebuild.sh
else
echo "Skipping CI prebuild"
fi
# Publish .NET Project
- name: Publish dotnet project
working-directory: ./world
run: |
dotnet publish -c Release /p:DEPLOY_API=${{ secrets.DEPLOY_API }}
# Authenticate, build and push to GitHub Container Registry (ghcr.io)
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Build and push new docker image, skip for manual redeploy other than 'latest'
- name: Build and push Docker images
uses: docker/[email protected]
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
with:
file: Dockerfile
context: .
push: true
tags: ghcr.io/${{ env.image_repository_name }}:${{ env.TAG_NAME }}

- name: Build and push Docker image
run: |
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
deploy_via_ssh:
needs: push_to_registry
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
if: ${{ github.event.workflow_run.conclusion != 'failure' }}
steps:
# Checkout latest or specific tag
- name: checkout
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: checkout tag
if: ${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }}
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: refs/tags/${{ github.event.inputs.version }}

# Assign environment variables used in subsequent steps
- name: repository name fix and env
run: |
echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
Expand All @@ -118,44 +87,43 @@ jobs:
echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
fi;
# Populate docker-compose.yml with variables from build process, including TAG_NAME.
- name: docker-compose file prep
uses: danielr1996/[email protected]
env:
RELEASE_VERSION: ${{ env.TAG_NAME }}
IMAGE_REPO: ${{ env.image_repository_name }}
APP_NAME: ${{ github.event.repository.name }}
HOST_DOMAIN: ${{ secrets.DEPLOY_API }}
LETSENCRYPT_EMAIL: ${{ secrets.LETSENCRYPT_EMAIL }}
DEPLOY_API: ${{ secrets.DEPLOY_API }}
with:
input: .deploy/docker-compose-template.yml
output: .deploy/${{ github.event.repository.name }}-docker-compose.yml

- name: Create .env file
run: |
echo "Generating .env file"
echo "# Autogenerated .env file" > .deploy/.env
echo "HOST_DOMAIN=${{ secrets.DEPLOY_HOST }}" >> .deploy/.env
echo "LETSENCRYPT_EMAIL=${{ secrets.LETSENCRYPT_EMAIL }}" >> .deploy/.env
echo "APP_NAME=${{ github.event.repository.name }}" >> .deploy/.env
echo "IMAGE_REPO=${{ env.image_repository_name }}" >> .deploy/.env
echo "RELEASE_VERSION=${{ env.TAG_NAME }}" >> .deploy/.env
# Copy only the docker-compose.yml to remote server home folder
- name: copy compose file via scp
- name: copy files to target server via scp
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEPLOY_API }}
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USERNAME }}
port: 22
key: ${{ secrets.DEPLOY_KEY }}
source: ".deploy/${{ github.event.repository.name }}-docker-compose.yml"
target: "~/"
strip_components: 2
source: "./.deploy/docker-compose.yml,./.deploy/.env"
target: "~/.deploy/${{ github.event.repository.name }}/"

# Deploy Docker image with ServiceStack application using `docker compose up` remotely
# Deploy Docker image with your application using `docker compose up` remotely
- name: remote docker-compose up via ssh
uses: appleboy/[email protected]
env:
APPTOKEN: ${{ secrets.GITHUB_TOKEN }}
USERNAME: ${{ secrets.DEPLOY_USERNAME }}
with:
host: ${{ secrets.DEPLOY_API }}
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USERNAME }}
key: ${{ secrets.DEPLOY_KEY }}
port: 22
envs: APPTOKEN,USERNAME
script: |
echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin
docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml pull
docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml up -d
cd ~/.deploy/${{ github.event.repository.name }}
docker compose pull
docker compose up app -d
1 change: 0 additions & 1 deletion world/Validation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<PublishProfile>DefaultContainer</PublishProfile>
</PropertyGroup>
Expand Down

0 comments on commit 8b8e208

Please sign in to comment.