Skip to content

Commit 12c35dd

Browse files
committed
Add deploy step
1 parent f139025 commit 12c35dd

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

.github/workflows/ci-cd.yml

+43
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,46 @@ jobs:
135135
cache-to: type=gha,mode=max,scope=global
136136
build-args:
137137
BASE_IMAGE=${{ env.base }}
138+
139+
deploy:
140+
name: Deploy
141+
if: (github.event_name == 'push') && (github.ref == 'refs/heads/mainnet' || github.ref == 'refs/heads/testnet')
142+
runs-on: ubuntu-latest
143+
needs:
144+
- build_api
145+
- build_web
146+
steps:
147+
- name: Prepare compose file with environment variables
148+
run: |
149+
if [ "${GITHUB_REF}" = "refs/heads/mainnet" ]; then
150+
sed -i 's/planbenvtoreplace/mainnet/g' docker/compose.yml
151+
else
152+
sed -i 's/planbenvtoreplace/testnet/g' docker/compose.yml
153+
fi
154+
env:
155+
GITHUB_REF: ${{ github.ref }}
156+
157+
- name: Copy Docker files to server
158+
uses: appleboy/scp-action@v0.1.7
159+
with:
160+
host: ${{ secrets.SERVER_HOST }}
161+
username: ${{ secrets.SERVER_USER }}
162+
key: ${{ secrets.SERVER_SSH_KEY }}
163+
source: 'docker/compose.yml,docker/cdn'
164+
overwrite: true
165+
strip_components: 1
166+
target: ${{ github.ref == 'refs/heads/mainnet' && 'mainnet' || 'testnet' }}
167+
168+
- name: Deploy to server
169+
uses: appleboy/ssh-action@v1.2.0
170+
with:
171+
host: ${{ secrets.SERVER_HOST }}
172+
username: ${{ secrets.SERVER_USER }}
173+
key: ${{ secrets.SERVER_SSH_KEY }}
174+
script_stop: true
175+
script: |
176+
cd ${{ github.ref == 'refs/heads/mainnet' && 'mainnet' || 'testnet' }}
177+
docker compose pull
178+
docker compose stop || true
179+
docker compose rm -f || true
180+
docker compose up -d

0 commit comments

Comments
 (0)