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 bc921d0 commit a27b1b9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
26 changes: 14 additions & 12 deletions .deploy/docker-compose-template.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
version: "3.9"
services:
${APP_NAME}:
image: ghcr.io/${IMAGE_REPO}:${RELEASE_VERSION}
restart: always
network_mode: bridge
ports:
- "80"
app:
image: ghcr.io/${IMAGE_REPO}:${RELEASE_VERSION}
restart: always
ports:
- "8080"
container_name: ${APP_NAME}_app
environment:
WS_HOST: ws://${HOST_DOMAIN}
WS_PORT: 80
VIRTUAL_HOST: ${HOST_DOMAIN}
LETSENCRYPT_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}
SERVICESTACK_LICENSE: ${SERVICESTACK_LICENSE}
FORUMS_DB: ${FORUMS_DB}
TECHSTACKS_SMTP_USER: ${TECHSTACKS_SMTP_USER}
TECHSTACKS_SMTP_PASS: ${TECHSTACKS_SMTP_PASS}
LC_ALL: "en_US.UTF-8"
LANG: "en_US.UTF-8"
volumes:
- ${APP_NAME}-mydb:/app/App_Data
- app-mydb:/app/App_Data

${APP_NAME}-migration:
image: ghcr.io/${IMAGE_REPO}:${RELEASE_VERSION}
restart: "no"
Expand Down
72 changes: 35 additions & 37 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: actions/checkout@v3
with:
ref: refs/tags/${{ github.event.inputs.version }}

# Assign environment variables used in subsequent steps
- name: Env variable assignment
run: echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
Expand All @@ -48,7 +48,7 @@ jobs:
if [ "${{ github.event.inputs.version }}" != "" ]; then
echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
fi;
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
Expand All @@ -74,14 +74,9 @@ jobs:
working-directory: ./TechStacks

# Build and push new docker image, skip for manual redeploy other than 'latest'
- name: Build and push Docker images
uses: docker/build-push-action@v4
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
Expand All @@ -101,8 +96,6 @@ jobs:
- name: repository name fix and env
run: |
echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "domain=${{ secrets.DEPLOY_HOST }}" >> $GITHUB_ENV
echo "letsencrypt_email=${{ secrets.LETSENCRYPT_EMAIL }}" >> $GITHUB_ENV
echo "TAG_NAME=latest" >> $GITHUB_ENV
if [ "${{ github.event.release.tag_name }}" != "" ]; then
echo "TAG_NAME=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
Expand All @@ -111,32 +104,32 @@ 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: ${{ env.domain }}
LETSENCRYPT_EMAIL: ${{ env.letsencrypt_email }}
FORUMS_DB: ${{ secrets.FORUMS_DB }}
TECHSTACKS_SMTP_USER: ${{ secrets.TECHSTACKS_SMTP_USER }}
TECHSTACKS_SMTP_PASS: ${{ secrets.TECHSTACKS_SMTP_PASS }}
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
echo "FORUMS_DB=${{ secrets.FORUMS_DB }}" >> .deploy/.env
echo "TECHSTACKS_SMTP_USER=${{ secrets.TECHSTACKS_SMTP_USER }}" >> .deploy/.env
echo "TECHSTACKS_SMTP_PASS=${{ secrets.TECHSTACKS_SMTP_PASS }}" >> .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_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 }}/"

- name: Run remote db migrations
uses: appleboy/[email protected]
env:
Expand All @@ -149,12 +142,16 @@ jobs:
port: 22
envs: APPTOKEN,USERNAME
script: |
set -e
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 ${{ github.event.repository.name }}-migration
# Deploy Docker image with ServiceStack application using `docker compose up` remotely
- name: remote docker compose up via ssh
cd ~/.deploy/${{ github.event.repository.name }}
docker compose pull
export APP_ID=$(docker compose run --entrypoint "id -u" --rm app)
docker compose run --entrypoint "chown $APP_ID:$APP_ID /app/App_Data" --user root --rm app
docker compose up app-migration --exit-code-from app-migration
# 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 }}
Expand All @@ -167,5 +164,6 @@ jobs:
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

0 comments on commit a27b1b9

Please sign in to comment.