2222
2323jobs :
2424 push_to_registry :
25- runs-on : ubuntu-20 .04
25+ runs-on : ubuntu-22 .04
2626 if : ${{ github.event.workflow_run.conclusion != 'failure' }}
2727 steps :
2828 # Checkout latest or specific tag
2929 - name : checkout
3030 if : ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
31- uses : actions/checkout@v2
31+ uses : actions/checkout@v3
3232 - name : checkout tag
3333 if : ${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }}
34- uses : actions/checkout@v2
34+ uses : actions/checkout@v3
3535 with :
3636 ref : refs/tags/${{ github.event.inputs.version }}
37-
38- - name : Setup dotnet
39- uses : actions/setup-dotnet@v1
40- with :
41- dotnet-version : ' 6.0'
42-
37+
4338 # Assign environment variables used in subsequent steps
44- - name : repository name fix
39+ - name : Env variable assignment
4540 run : echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
4641 # TAG_NAME defaults to 'latest' if not a release or manual deployment
4742 - name : Assign version
@@ -54,39 +49,33 @@ jobs:
5449 echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
5550 fi;
5651
57- # Authenticate, build and push to GitHub Container Registry (ghcr.io)
5852 - name : Login to GitHub Container Registry
59- uses : docker/login-action@v1
53+ uses : docker/login-action@v2
6054 with :
6155 registry : ghcr.io
62- username : ${{ github.repository_owner }}
56+ username : ${{ github.actor }}
6357 password : ${{ secrets.GITHUB_TOKEN }}
64-
58+
6559 # Build and push new docker image, skip for manual redeploy other than 'latest'
66- - name : Build and push Docker images
67- uses : docker/build-push-action@v2.2.2
68- if : ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
69- with :
70- file : ./src/Dockerfile
71- context : ./src
72- push : true
73- tags : ghcr.io/${{ env.image_repository_name }}:${{ env.TAG_NAME }}
74-
60+ - name : Build and push Docker image
61+ run : |
62+ 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
63+
7564 deploy_via_ssh :
7665 needs : push_to_registry
77- runs-on : ubuntu-20 .04
66+ runs-on : ubuntu-22 .04
7867 if : ${{ github.event.workflow_run.conclusion != 'failure' }}
7968 steps :
69+ # Checkout latest or specific tag
8070 - name : checkout
8171 if : ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
82- uses : actions/checkout@v2
72+ uses : actions/checkout@v3
8373 - name : checkout tag
8474 if : ${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }}
85- uses : actions/checkout@v2
75+ uses : actions/checkout@v3
8676 with :
8777 ref : refs/tags/${{ github.event.inputs.version }}
8878
89- # Assign environment variables used in subsequent steps
9079 - name : repository name fix and env
9180 run : |
9281 echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
@@ -97,56 +86,46 @@ jobs:
9786 if [ "${{ github.event.inputs.version }}" != "" ]; then
9887 echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
9988 fi;
100- - name : docker-compose file prep
101- uses : danielr1996/envsubst-action@1.0.0
102- env :
103- RELEASE_VERSION : ${{ env.TAG_NAME }}
104- IMAGE_REPO : ${{ env.image_repository_name }}
105- APP_NAME : ${{ github.event.repository.name }}
106- HOST_DOMAIN : ${{ secrets.DEPLOY_API }}
107- LETSENCRYPT_EMAIL : ${{ secrets.LETSENCRYPT_EMAIL }}
108- with :
109- input : .deploy/docker-compose-template.yml
110- output : .deploy/${{ github.event.repository.name }}-docker-compose.yml
11189
112- - name : copy compose file via scp
90+ - name : Create .env file
91+ run : |
92+ echo "Generating .env file"
93+
94+ echo "# Autogenerated .env file" > .deploy/.env
95+ echo "HOST_DOMAIN=${{ secrets.DEPLOY_HOST }}" >> .deploy/.env
96+ echo "LETSENCRYPT_EMAIL=${{ secrets.LETSENCRYPT_EMAIL }}" >> .deploy/.env
97+ echo "APP_NAME=${{ github.event.repository.name }}" >> .deploy/.env
98+ echo "IMAGE_REPO=${{ env.image_repository_name }}" >> .deploy/.env
99+ echo "RELEASE_VERSION=${{ env.TAG_NAME }}" >> .deploy/.env
100+
101+ # Copy only the docker-compose.yml to remote server home folder
102+ - name : copy files to target server via scp
113103 uses : appleboy/scp-action@v0.1.3
114104 with :
115- host : ${{ secrets.DEPLOY_API }}
105+ host : ${{ secrets.DEPLOY_HOST }}
116106 username : ${{ secrets.DEPLOY_USERNAME }}
117107 port : 22
118108 key : ${{ secrets.DEPLOY_KEY }}
119- source : " .deploy/${{ github.event.repository.name }}-docker-compose.yml"
120- target : " ~/"
121-
122- - name : Run remote db migrations
123- uses : appleboy/ssh-action@v0.1.4
124- env :
125- APPTOKEN : ${{ secrets.GITHUB_TOKEN }}
126- USERNAME : ${{ secrets.DEPLOY_USERNAME }}
127- with :
128- host : ${{ secrets.DEPLOY_API }}
129- username : ${{ secrets.DEPLOY_USERNAME }}
130- key : ${{ secrets.DEPLOY_KEY }}
131- port : 22
132- envs : APPTOKEN,USERNAME
133- script : |
134- echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin
135- docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml pull
136- docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml up ${{ github.event.repository.name }}-migration
109+ strip_components : 2
110+ source : " ./.deploy/docker-compose.yml,./.deploy/.env"
111+ target : " ~/.deploy/${{ github.event.repository.name }}/"
137112
113+ # Deploy Docker image with your application using `docker compose up` remotely
138114 - name : remote docker-compose up via ssh
139- uses : appleboy/ssh-action@v0.1.4
115+ uses : appleboy/ssh-action@v0.1.5
140116 env :
141117 APPTOKEN : ${{ secrets.GITHUB_TOKEN }}
142118 USERNAME : ${{ secrets.DEPLOY_USERNAME }}
143119 with :
144- host : ${{ secrets.DEPLOY_API }}
120+ host : ${{ secrets.DEPLOY_HOST }}
145121 username : ${{ secrets.DEPLOY_USERNAME }}
146122 key : ${{ secrets.DEPLOY_KEY }}
147- port : ${{ secrets.DEPLOY_PORT }}
123+ port : 22
148124 envs : APPTOKEN,USERNAME
149125 script : |
150126 echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin
151- docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml pull
152- docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml up -d
127+ cd ~/.deploy/${{ github.event.repository.name }}
128+ docker compose pull
129+ export APP_ID=$(docker compose run --entrypoint "id -u" --rm app)
130+ docker compose run --entrypoint "chown $APP_ID:$APP_ID /app/App_Data" --user root --rm app
131+ docker compose up app -d
0 commit comments