-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add runners for deployment and base image builds (#6)
- Loading branch information
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ PORT=3001 | |
TEST_REPO_URL=https://github.com/nully0x/test-repo | ||
TEST_REPO_BRANCH=main | ||
TEST_REPO_PATH=tests | ||
BASE_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Build Base Images | ||
|
||
on: | ||
workflow_dispatch: # Manual trigger | ||
push: | ||
paths: | ||
- "baseImages/**" | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-base-images: | ||
name: Build Base Images on Droplet | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
image: | ||
- { name: "rust", tag: "rs-base", path: "baseImages/rust" } | ||
- { | ||
name: "typescript", | ||
tag: "ts-base", | ||
path: "baseImages/typescript", | ||
} | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure SSH | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "${{ secrets.STAGING_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | ||
chmod 600 ~/.ssh/id_rsa | ||
ssh-keyscan -H ${{ secrets.STAGING_DROPLET_IP }} >> ~/.ssh/known_hosts | ||
# Create directory and copy Dockerfile | ||
- name: Copy Dockerfile to Droplet | ||
run: | | ||
ssh ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }} "mkdir -p ~/base-images/${{ matrix.image.name }}" | ||
scp ${{ matrix.image.path }}/Dockerfile ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }}:~/base-images/${{ matrix.image.name }}/Dockerfile | ||
# Build the image on the droplet | ||
- name: Build Base Image | ||
run: | | ||
ssh ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }} << 'EOF' | ||
cd ~/base-images/${{ matrix.image.name }} | ||
docker build -t ${{ matrix.image.tag }}:latest . | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Deploy to DigitalOcean | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
name: Build and Deploy Node.js App | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "18" | ||
|
||
- name: Configure SSH | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "${{ secrets.STAGING_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | ||
chmod 600 ~/.ssh/id_rsa | ||
ssh-keyscan -H ${{ secrets.STAGING_DROPLET_IP }} >> ~/.ssh/known_hosts | ||
- name: Install Dependencies and Build | ||
run: | | ||
yarn install | ||
yarn build | ||
ls dist # Debug: Check if dist directory exists and its contents | ||
# Create necessary directories first | ||
- name: Create Remote Directories | ||
run: | | ||
ssh ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }} "mkdir -p ~/node-app/dist" | ||
# Then copy files | ||
- name: Copy Built Files to Droplet | ||
run: | | ||
scp -r dist/* ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }}:~/node-app/dist/ | ||
scp package.json ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }}:~/node-app/ | ||
scp yarn.lock ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }}:~/node-app/ | ||
- name: Set Up .env File | ||
run: | | ||
ssh ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }} "echo '${{ secrets.STAGING_RUNNER_SECRET_FILE }}' > ~/node-app/.env" | ||
- name: Install Dependencies and Start App | ||
run: | | ||
ssh ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }} << 'EOF' | ||
cd ~/node-app | ||
yarn install --production | ||
ls dist # Debug: Check if dist directory exists on server | ||
if pm2 list | grep -q node-app; then | ||
echo "Restarting existing app..." | ||
pm2 restart node-app | ||
else | ||
echo "Starting new app..." | ||
pm2 start dist/server.js --name node-app | ||
fi | ||
pm2 save | ||
EOF |