|
1 | 1 | name: Angular CI/CD |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - branches: |
6 | | - - master |
7 | | - workflow_dispatch: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + workflow_dispatch: |
8 | 8 |
|
9 | 9 | jobs: |
10 | | - build: |
11 | | - runs-on: ubuntu-latest |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout repository |
| 14 | + uses: actions/checkout@v4 |
| 15 | + - name: Use Node.js |
| 16 | + uses: actions/setup-node@v4 |
| 17 | + with: |
| 18 | + node-version: '18' |
| 19 | + - name: Install dependencies |
| 20 | + run: npm install |
| 21 | + - name: Build the Angular app |
| 22 | + run: npm run build-prod |
| 23 | + - name: Compress dist folder |
| 24 | + run: tar -czf dist.tar.gz dist/ |
| 25 | + - name: Upload artifact |
| 26 | + |
| 27 | + with: |
| 28 | + name: dist |
| 29 | + path: dist.tar.gz |
| 30 | + deploy: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - name: Download artifact |
| 34 | + uses: actions/download-artifact@v4 |
| 35 | + with: |
| 36 | + name: dist |
| 37 | + - name: Add SSH private key to the agent |
| 38 | + env: |
| 39 | + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} |
| 40 | + run: | |
| 41 | + mkdir -p ~/.ssh |
| 42 | + echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa |
| 43 | + chmod 600 ~/.ssh/id_rsa |
| 44 | + ssh-keyscan -H ${{ secrets.REMOTE_HOST }} >> ~/.ssh/known_hosts |
| 45 | + chmod 644 ~/.ssh/known_hosts |
| 46 | + - name: Copy files to server |
| 47 | + uses: appleboy/scp-action@master |
| 48 | + with: |
| 49 | + host: ${{ secrets.REMOTE_HOST }} |
| 50 | + username: ${{ secrets.REMOTE_USER }} |
| 51 | + key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 52 | + port: 22 |
| 53 | + source: "dist.tar.gz" |
| 54 | + target: "/root/" |
| 55 | + - name: Run deployment script on server |
| 56 | + uses: appleboy/ssh-action@master |
| 57 | + with: |
| 58 | + host: ${{ secrets.REMOTE_HOST }} |
| 59 | + username: ${{ secrets.REMOTE_USER }} |
| 60 | + key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 61 | + port: 22 |
| 62 | + script: | |
| 63 | + cd /root |
| 64 | + rm -rf aqua-viewer |
| 65 | + tar -zxvf dist.tar.gz |
| 66 | + docker exec -it nginx rm -rf /var/www/portal |
| 67 | + docker cp aqua-viewer nginx:/var/www/portal |
| 68 | + docker restart nginx |
| 69 | +
|
| 70 | + |
12 | 71 |
|
13 | | - steps: |
14 | | - - name: Checkout repository |
15 | | - uses: actions/checkout@v4 |
16 | | - - name: Use Node.js |
17 | | - uses: actions/setup-node@v4 |
18 | | - with: |
19 | | - node-version: '18' |
20 | | - - name: Install dependencies |
21 | | - run: npm install |
22 | | - - name: Build the Angular app |
23 | | - run: npm run build-prod |
24 | | - - name: Compress dist folder |
25 | | - run: tar -czf dist.tar.gz dist/ |
26 | | - - name: Upload artifact |
27 | | - |
28 | | - with: |
29 | | - name: dist |
30 | | - path: dist.tar.gz |
|
0 commit comments