From 8b8e208a88e9a0dafeddeefd1628d4679706bdcb Mon Sep 17 00:00:00 2001 From: Demis Bellot Date: Tue, 16 Jan 2024 21:20:14 +0800 Subject: [PATCH] upgrade to latest build scripts --- .deploy/docker-compose-template.yml | 17 ----- .deploy/docker-compose.yml | 28 ++++++++ .deploy/nginx-proxy-compose.yml | 22 +++--- .github/workflows/release.yml | 100 ++++++++++------------------ world/Validation.csproj | 1 - 5 files changed, 76 insertions(+), 92 deletions(-) delete mode 100644 .deploy/docker-compose-template.yml create mode 100644 .deploy/docker-compose.yml diff --git a/.deploy/docker-compose-template.yml b/.deploy/docker-compose-template.yml deleted file mode 100644 index 30f3fb0..0000000 --- a/.deploy/docker-compose-template.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: "3.9" -services: - ${APP_NAME}: - image: ghcr.io/${IMAGE_REPO}:${RELEASE_VERSION} - restart: always - ports: - - "80" - environment: - VIRTUAL_HOST: ${HOST_DOMAIN} - LETSENCRYPT_HOST: ${HOST_DOMAIN} - LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL} - DEPLOY_API: ${DEPLOY_API} - -networks: - default: - external: true - name: nginx diff --git a/.deploy/docker-compose.yml b/.deploy/docker-compose.yml new file mode 100644 index 0000000..de6e2d2 --- /dev/null +++ b/.deploy/docker-compose.yml @@ -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: diff --git a/.deploy/nginx-proxy-compose.yml b/.deploy/nginx-proxy-compose.yml index eccae8d..14a709c 100644 --- a/.deploy/nginx-proxy-compose.yml +++ b/.deploy/nginx-proxy-compose.yml @@ -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: @@ -15,21 +15,27 @@ 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: - DEFAULT_EMAIL=you@example.com - 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: @@ -37,4 +43,4 @@ volumes: html: dhparam: certs: - acme: + acme: \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e948a3e..60f0ecb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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/build-push-action@v2.2.2 - 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 @@ -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/envsubst-action@1.1.0 - 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/scp-action@v0.1.3 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/ssh-action@v0.1.5 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 diff --git a/world/Validation.csproj b/world/Validation.csproj index e6a8e15..f9106aa 100644 --- a/world/Validation.csproj +++ b/world/Validation.csproj @@ -4,7 +4,6 @@ net8.0 enable enable - InProcess true DefaultContainer