-
Notifications
You must be signed in to change notification settings - Fork 1
104 lines (96 loc) · 4.46 KB
/
deploy_CI.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Deploy
on:
push:
branches:
- develop
tags:
- '*-beta*'
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
if: contains('
refs/heads/master
refs/heads/develop
', github.ref) || ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+.[0-9]+.[0-9]+-beta* || ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+.[0-9]+.[0-9]+
steps:
- uses: actions/checkout@v3.5.0
- name: zip deploy script
run: |
mkdir deploy_script
cp deploy.sh deploy_script
tar -cvf deploy.tar deploy_script
- name: Set BRANCH env
shell: bash
run: echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
id: extract_branch
- name: Get Version
if: ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+.[0-9]+.[0-9]
run: echo "TAG=$(echo $GITHUB_REF | cut -d / -f 3)" >> $GITHUB_ENV
- name: Set env for production if release and not beta
if: startsWith(github.ref, 'refs/tags/v') && ( contains(env.TAG, '-beta') != true )
run: |
echo "ENVIRONMENT=${{ secrets.PROD_ENV }}" >> $GITHUB_ENV
echo "HOST=${{ secrets.PROD_HOST }}" >> $GITHUB_ENV
echo "USERNAME=${{ secrets.USERNAME }}" >> $GITHUB_ENV
echo "WWW_SITE_URL=www.devinit.org" >> $GITHUB_ENV
echo "SITE_URL=devinit.org" >> $GITHUB_ENV
echo "DATA_SITE_URL=data.devinit.org" >> $GITHUB_ENV
echo "USE_SPACES=TRUE" >> $GITHUB_ENV
echo "AWS_S3_ENDPOINT_URL=${{ secrets.PROD_S3_ENDPOINT_URL }}" >> $GITHUB_ENV
echo "AWS_STORAGE_BUCKET_NAME=${{ secrets.PROD_STORAGE_BUCKET_NAME }}" >> $GITHUB_ENV
echo "AWS_ACCESS_KEY_ID=${{ secrets.PROD_S3_ACCESS_KEY_ID }}" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.PROD_S3_SECRET_ACCESS_KEY }}" >> $GITHUB_ENV
- name: Set env for staging or dev
if: endsWith(github.ref, '/develop') || contains(env.TAG, '-beta')
run: |
echo "ENVIRONMENT=${{ secrets.DEV_ENV }}" >> $GITHUB_ENV
echo "HOST=${{ secrets.DEV_HOST }}" >> $GITHUB_ENV
echo "USERNAME=${{ secrets.USERNAME }}" >> $GITHUB_ENV
echo "WWW_SITE_URL=dev.devinit.org" >> $GITHUB_ENV
echo "SITE_URL=dev.devinit.org" >> $GITHUB_ENV
echo "DATA_SITE_URL=dev.devinit.org" >> $GITHUB_ENV
echo "USE_SPACES=TRUE" >> $GITHUB_ENV
echo "AWS_S3_ENDPOINT_URL=${{ secrets.DEV_S3_ENDPOINT_URL }}" >> $GITHUB_ENV
echo "AWS_STORAGE_BUCKET_NAME=${{ secrets.DEV_STORAGE_BUCKET_NAME }}" >> $GITHUB_ENV
echo "AWS_ACCESS_KEY_ID=${{ secrets.DEV_S3_ACCESS_KEY_ID }}" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.DEV_S3_SECRET_ACCESS_KEY }}" >> $GITHUB_ENV
- name: copy deploy file via ssh
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ env.HOST }}
username: ${{ env.USERNAME }}
port: ${{ secrets.PORT }}
key: ${{ secrets.KEY }}
source: 'deploy_script'
target: '.'
- name: run deployment
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ env.HOST }}
username: ${{ env.USERNAME }}
port: ${{ secrets.PORT }}
key: ${{ secrets.KEY }}
command_timeout: 30m
script: |
export BRANCH=${{ env.BRANCH }}
export SECRET_KEY="${{ secrets.SECRET_KEY }}"
export ENVIRONMENT=${{ env.ENVIRONMENT }}
export DATABASE_URL=${{ secrets.DATABASE_URL }}
export DEFAULT_FROM_EMAIL=${{ secrets.DEFAULT_FROM_EMAIL }}
export EMAIL_HOST=${{ secrets.EMAIL_HOST }}
export EMAIL_BACKEND=${{ secrets.EMAIL_BACKEND }}
export EMAIL_HOST_USER=${{ secrets.EMAIL_HOST_USER }}
export EMAIL_HOST_PASSWORD=${{secrets.EMAIL_HOST_PASSWORD }}
export GITHUB_TOKEN=${{ secrets.TOKEN_GITHUB }}
export SITE_URL=${{ env.SITE_URL }}
export WWW_SITE_URL=${{ env.WWW_SITE_URL }}
export DATA_SITE_URL=${{ env.DATA_SITE_URL }}
export USE_SPACES=${{ env.USE_SPACES }}
export AWS_S3_ENDPOINT_URL=${{ env.AWS_S3_ENDPOINT_URL }}
export AWS_STORAGE_BUCKET_NAME=${{ env.AWS_STORAGE_BUCKET_NAME }}
export AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}
export AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }}
cp -r deploy_script/deploy.sh .
chmod +x deploy.sh && ./deploy.sh run