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-
37+
3838 # Assign environment variables used in subsequent steps
3939 - name : Env variable assignment
4040 run : echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
@@ -58,44 +58,42 @@ jobs:
5858 run : |
5959 npm run build
6060 working-directory : ./MyApp
61-
61+
6262 - name : Login to GitHub Container Registry
63- uses : docker/login-action@v1
63+ uses : docker/login-action@v2
6464 with :
6565 registry : ghcr.io
6666 username : ${{ github.actor }}
6767 password : ${{ secrets.GITHUB_TOKEN }}
6868
6969 # Build and push new docker image, skip for manual redeploy other than 'latest'
7070 - name : Build and push Docker images
71- uses : docker/build-push-action@v2.2.2
71+ uses : docker/build-push-action@v3
7272 if : ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
7373 with :
7474 file : Dockerfile
7575 context : .
7676 push : true
7777 tags : ghcr.io/${{ env.image_repository_name }}:${{ env.TAG_NAME }}
78-
78+
7979 deploy_via_ssh :
8080 needs : push_to_registry
81- runs-on : ubuntu-20 .04
81+ runs-on : ubuntu-22 .04
8282 if : ${{ github.event.workflow_run.conclusion != 'failure' }}
8383 steps :
8484 # Checkout latest or specific tag
8585 - name : checkout
8686 if : ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}
87- uses : actions/checkout@v2
87+ uses : actions/checkout@v3
8888 - name : checkout tag
8989 if : ${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }}
90- uses : actions/checkout@v2
90+ uses : actions/checkout@v3
9191 with :
9292 ref : refs/tags/${{ github.event.inputs.version }}
9393
9494 - name : repository name fix and env
9595 run : |
9696 echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
97- echo "domain=${{ secrets.DEPLOY_HOST }}" >> $GITHUB_ENV
98- echo "letsencrypt_email=${{ secrets.LETSENCRYPT_EMAIL }}" >> $GITHUB_ENV
9997 echo "TAG_NAME=latest" >> $GITHUB_ENV
10098 if [ "${{ github.event.release.tag_name }}" != "" ]; then
10199 echo "TAG_NAME=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
@@ -104,33 +102,31 @@ jobs:
104102 echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV
105103 fi;
106104
107- # Populate docker-compose.yml with variables from build process, including TAG_NAME.
108- - name : docker-compose file prep
109- uses :
danielr1996/[email protected] 110- env :
111- RELEASE_VERSION : ${{ env.TAG_NAME }}
112- IMAGE_REPO : ${{ env.image_repository_name }}
113- APP_NAME : ${{ github.event.repository.name }}
114- HOST_DOMAIN : ${{ env.domain }}
115- LETSENCRYPT_EMAIL : ${{ env.letsencrypt_email }}
116- with :
117- input : .deploy/docker-compose-template.yml
118- output : .deploy/${{ github.event.repository.name }}-docker-compose.yml
105+ - name : Create .env file
106+ run : |
107+ echo "Generating .env file"
108+
109+ echo "#Autogenerated .env file" > .env
110+ echo "HOST_DOMAIN=${{ secrets.DEPLOY_HOST }}" >> .env
111+ echo "LETSENCRYPT_EMAIL=${{ secrets.LETSENCRYPT_EMAIL }}" >> .env
112+ echo "APP_NAME=${{ github.event.repository.name }}" >> .env
113+ echo "IMAGE_REPO=${{ env.image_repository_name }}" >> .env
114+ echo "RELEASE_VERSION=${{ env.TAG_NAME }}" >> .env
119115
120116 # Copy only the docker-compose.yml to remote server home folder
121- - name : copy compose file via scp
117+ - name : copy files to target server via scp
122118123119 with :
124120 host : ${{ secrets.DEPLOY_HOST }}
125121 username : ${{ secrets.DEPLOY_USERNAME }}
126122 port : 22
127123 key : ${{ secrets.DEPLOY_KEY }}
128- source : " .deploy/${{ github.event.repository.name }}- docker-compose.yml"
129- target : " ~/"
124+ source : " ./docker-compose.yml,./ docker-compose.prod. yml,./.env "
125+ target : " ~/.deploy/${{ github.event.repository.name }}/ "
130126
131- # Deploy Docker image with ServiceStack application using `docker compose up` remotely
127+ # Deploy Docker image with your application using `docker compose up` remotely
132128 - name : remote docker-compose up via ssh
133- uses :
appleboy/[email protected] .4 129+ uses :
appleboy/[email protected] .5 134130 env :
135131 APPTOKEN : ${{ secrets.GITHUB_TOKEN }}
136132 USERNAME : ${{ secrets.DEPLOY_USERNAME }}
@@ -142,5 +138,6 @@ jobs:
142138 envs : APPTOKEN,USERNAME
143139 script : |
144140 echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin
145- docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml pull
146- docker-compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml up -d
141+ cd ~/.deploy/${{ github.event.repository.name }}
142+ docker compose -f ./docker-compose.yml -f ./docker-compose.prod.yml pull
143+ docker compose -f ./docker-compose.yml -f ./docker-compose.prod.yml up app -d
0 commit comments