Skip to content
Open

tita #100

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .github/workflows/npm-publish-github-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: CD-TP-admin2-Backend
on:
push:
branches:
- release

pull_request:
branches:
- release

release:
types: [created, published]

jobs:
build:
runs-on: ubuntu-latest
environment: envdev

strategy:
matrix:
node-version: [ 22 ]

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- run: npm install

- run: CI=false npm run build --if-present

- name: Upload build artifact
uses: actions/upload-artifact@v5
with:
name: tp-admin2-backend-app-artifact-${{ github.run_number }}
path: dist/

deploy:
runs-on: ubuntu-latest
environment: envdev
needs: build

steps:
- name: Download build artifact
uses: actions/download-artifact@v6.0.0
with:
name: tp-admin2-backend-app-artifact-${{ github.run_number }}
path: ./artifact-files

- name: Show downloaded files
run: ls -R ./artifact-files

- name: Setup SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/deploy-key.pem
chmod 600 ~/.ssh/deploy-key.pem
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts

- name: Copy build files to EC2 server
run: |
# Create .env file from GitHub secret envirnoment envdev
echo "${{ secrets.ENV_FILE }}" > .env

# Copy artifacts + .env to EC2
scp -i ~/.ssh/deploy-key.pem -r ./artifact-files/* .env \
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/ubuntu/admin2-backend


- name: Restart app on EC2
run: |
ssh -i ~/.ssh/deploy-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
# Load NVM so PM2 becomes available
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

pm2 restart trustlypay_admin2_backend_1.0 || echo "PM2 not found!"
pm2 list || echo "PM2 list failed!"

sudo systemctl restart apache2
sudo systemctl status apache2 --no-pager
EOF
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const port = process.env.PORT || 3000;

const server = http.createServer((req, res) => {
res.statusCode = 200;
const msg = 'Hello Node!\n'
const msg = 'Hello Node Application!\n'
res.end(msg);
});

Expand Down