forked from IQSS/dataverse-frontend
-
Notifications
You must be signed in to change notification settings - Fork 1
149 lines (124 loc) · 4.7 KB
/
deploy.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: deploy
on:
workflow_dispatch:
inputs:
infra_type:
description: Remote infrastructure type
type: choice
required: true
options:
- S3
- Payara
environment:
description: Environment to run the deployment against
type: environment
required: true
basepath:
description: 'Server basepath, without slashes, to serve the application (For example: spa). This is only for Payara deployment, and should be left blank if a basepath is not needed.'
type: string
required: false
jobs:
build:
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Create .npmrc
run: |
cp .npmrc.example .npmrc
sed -i -e 's/<YOUR_GITHUB_AUTH_TOKEN>/${{ secrets.GITHUB_TOKEN }}/g' .npmrc
sed -i -e 's/<YOUR_NPM_AUTH_TOKEN>/${{ secrets.NPM_AUTH_TOKEN }}/g' .npmrc
- name: Install Dependencies
run: npm install
- name: Build Dataverse UI Library
working-directory: packages/design-system
run: npm run build
- name: Create and populate .env file
env:
DATAVERSE_BACKEND_URL: ${{ secrets.DATAVERSE_BACKEND_URL }}
run: |
touch .env
echo VITE_DATAVERSE_BACKEND_URL="$DATAVERSE_BACKEND_URL" >> .env
shell: bash
- name: Build
if: ${{ github.event.inputs.infra_type == 'S3' || (github.event.inputs.infra_type == 'Payara' && github.event.inputs.basepath == '') }}
run: npm run build
- name: Build with base path
if: ${{ github.event.inputs.infra_type == 'Payara' && github.event.inputs.basepath != '' }}
run: npm run build -- --base=/${{ github.event.inputs.basepath }}
- uses: actions/upload-artifact@v3
with:
name: built-site
path: ./dist
deploy-to-s3:
needs: build
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment }}
if: ${{ github.event.inputs.infra_type == 'S3' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install awscli
run: |
python -m pip install --upgrade pip
pip install awscli
- uses: actions/download-artifact@v3
with:
name: built-site
path: ./dist
- name: Upload to S3
run: |
aws s3 sync ./dist s3://${{ secrets.AWS_S3_BUCKET_NAME }} --delete
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
deploy-to-payara:
needs: build
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment }}
if: ${{ github.event.inputs.infra_type == 'Payara' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
- uses: actions/download-artifact@v3
with:
name: built-site
path: ./dist
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v6
- name: Build war file
working-directory: ./deployment/payara
run: mvn package "-Dversion=${{ steps.branch-name.outputs.current_branch }}"
- name: Copy war file to remote instance
uses: appleboy/scp-action@master
with:
host: ${{ secrets.PAYARA_INSTANCE_HOST }}
username: ${{ secrets.PAYARA_INSTANCE_USERNAME }}
key: ${{ secrets.PAYARA_INSTANCE_SSH_PRIVATE_KEY }}
source: './deployment/payara/target/dataverse-frontend.war'
target: '/home/${{ secrets.PAYARA_INSTANCE_USERNAME }}'
overwrite: true
- name: Execute payara war deployment remotely
uses: appleboy/[email protected]
with:
host: ${{ secrets.PAYARA_INSTANCE_HOST }}
username: ${{ secrets.PAYARA_INSTANCE_USERNAME }}
key: ${{ secrets.PAYARA_INSTANCE_SSH_PRIVATE_KEY }}
script: |
APPLICATION_NAME=dataverse-frontend
APPLICATION_WAR_PATH=deployment/payara/target/$APPLICATION_NAME.war
ASADMIN='/usr/local/payara6/bin/asadmin --user admin'
DATAVERSE_FRONTEND=`$ASADMIN list-applications |grep $APPLICATION_NAME |awk '{print $1}'`
$ASADMIN undeploy $DATAVERSE_FRONTEND
$ASADMIN deploy --name $APPLICATION_NAME --contextroot /${{ github.event.inputs.basepath }} $APPLICATION_WAR_PATH