Skip to content

Commit

Permalink
Update docker compose deploy related files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed Aug 8, 2023
1 parent 92b44b7 commit 6700bf1
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 53 deletions.
12 changes: 0 additions & 12 deletions .deploy/docker-compose-template.yml

This file was deleted.

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:
55 changes: 22 additions & 33 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ on:

jobs:
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
Expand All @@ -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 @@ -49,26 +49,16 @@ jobs:
echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
fi;
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
# Run postinstall script
- name: Install and build npm
run: |
npm install
working-directory: ./MyApp

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
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
uses: docker/build-push-action@v3
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
with:
file: Dockerfile
Expand All @@ -78,7 +68,7 @@ jobs:

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
Expand All @@ -104,31 +94,29 @@ 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 }}
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" > .env
echo "HOST_DOMAIN=${{ secrets.DEPLOY_HOST }}" >> .env
echo "LETSENCRYPT_EMAIL=${{ secrets.LETSENCRYPT_EMAIL }}" >> .env
echo "APP_NAME=${{ github.event.repository.name }}" >> .env
echo "IMAGE_REPO=${{ env.image_repository_name }}" >> .env
echo "RELEASE_VERSION=${{ env.TAG_NAME }}" >> .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: "~/"
source: "./docker-compose.yml,./docker-compose.prod.yml,./.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:
Expand All @@ -142,5 +130,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 -f ./docker-compose.yml -f ./docker-compose.prod.yml pull
docker compose -f ./docker-compose.yml -f ./docker-compose.prod.yml up app -d
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
WORKDIR /app

RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -y --no-install-recommends nodejs \
&& echo "node version: $(node --version)" \
&& echo "npm version: $(npm --version)" \
&& rm -rf /var/lib/apt/lists/*

COPY . .
RUN dotnet restore

WORKDIR /app/MyApp
RUN npm cache clean --force
RUN npm install && npm run postinstall
RUN dotnet publish -c release -o /out --no-restore

FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal AS runtime
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "3.9"
services:
app:
build: .
ports:
- "5000:80"
17 changes: 17 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.9"
services:
app:
image: ghcr.io/${IMAGE_REPO}:${RELEASE_VERSION}
restart: always
ports:
- "80"
container_name: ${APP_NAME}_app
environment:
VIRTUAL_HOST: ${HOST_DOMAIN}
LETSENCRYPT_HOST: ${HOST_DOMAIN}
LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}

networks:
default:
external: true
name: nginx
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: "3.9"
services:
app:
container_name: my_app

0 comments on commit 6700bf1

Please sign in to comment.