55 push :
66 branches :
77 - ' main'
8+ - ' staging'
89 tags :
910 - ' v*'
1011 pull_request :
1112 branches :
1213 - ' main'
14+ - ' staging'
1315
1416jobs :
1517 build :
@@ -50,21 +52,41 @@ jobs:
5052
5153 deploy :
5254 runs-on : ubuntu-latest
55+ permissions :
56+ contents : read
57+ packages : read
5358 needs : build
54- if : github.ref == 'refs/heads/main'
59+ strategy :
60+ matrix :
61+ include :
62+ - environment : staging
63+ branch : staging
64+ target_path : " ~/staging.mapdb.cncnet.org"
65+ compose_file : " docker-compose.prod.yml"
66+ nginx_conf : " docker/nginx.prod.conf"
67+ # disabled for now
68+ # - environment: production
69+ # branch: main
70+ # target_path: "~/prod2.mapdb.cncnet.org"
71+ # compose_file: "docker-compose.prod.yml"
72+ # nginx_conf: "docker/nginx.prod.conf"
5573
5674 steps :
75+ - name : " Exit if not matching branch"
76+ if : github.ref != format('refs/heads/{0}', matrix.branch)
77+ run : echo "Not target branch for this deployment. Skipping..." && exit 0
78+
5779 - name : Checkout repository
5880 uses : actions/checkout@v4
5981
60- - name : Copy docker-compose file over ssh
82+ - name : Copy docker-compose and nginx config over ssh
61836284 with :
6385 host : ${{ secrets.SSH_HOST }}
6486 username : ${{ secrets.SSH_USER }}
6587 key : ${{ secrets.SSH_PRIVATE_KEY }}
66- source : " docker-compose.prod.yml "
67- target : " ~/staging.mapdb.cncnet.org "
88+ source : " ${{ matrix.compose_file }},${{ matrix.nginx_conf }} "
89+ target : " ${{ matrix.target_path }} "
6890
6991 - name : SSH into server and deploy
70927395 username : ${{ secrets.SSH_USER }}
7496 key : ${{ secrets.SSH_PRIVATE_KEY }}
7597 script : |
76- cd ~/staging.mapdb.cncnet.org
98+ cd ${{ matrix.target_path }}
7799 echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
78- docker compose -f docker-compose.prod.yml pull
79- docker compose -f docker-compose.prod.yml down
80- docker compose -f docker-compose.prod.yml up -d
100+ docker compose -f ${{ matrix.compose_file }} pull
101+ docker compose -f ${{ matrix.compose_file }} down
102+ docker compose -f ${{ matrix.compose_file }} up -d
0 commit comments