Skip to content

[ Deploy ] v1.1.0 GroupPage (#173) #40

[ Deploy ] v1.1.0 GroupPage (#173)

[ Deploy ] v1.1.0 GroupPage (#173) #40

Workflow file for this run

name: Production build / Deployment
on:
push:
branches:
- deploy
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup Pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Restore next cache
uses: actions/cache@v4
id: cache
with:
path: |
.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/pnpm-lock.yaml') }}-
- name: Cache node modules
id: cache-node
uses: actions/cache@v4
with:
path: |
**/node_modules
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json', '**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.OS }}-node-
- name: Install Dependencies
if: steps.cache-node.outputs.cache-hit != 'true'
run: pnpm install
- name: Build with Next.js
run: pnpm build
- name: Make zip file
run: zip -r algohub.zip . -x "node_modules/*"
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: algohub
path: algohub.zip
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: algohub
path: algohub.zip
- name: Get Github action IP
id: ip
uses: haythem/[email protected]
- name: Setting environment variables
run: |
echo "AWS_DEFAULT_REGION=ap-northeast-2" >> $GITHUB_ENV
echo "AWS_SG_NAME=algohub" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_IAM_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_IAM_SECRET_KEY }}
aws-region: ap-northeast-2
- name: Add Github Actions IP to Security group
run: |
aws ec2 authorize-security-group-ingress --group-name ${{ env.AWS_SG_NAME }} --protocol tcp --port ${{ secrets.AWS_SSH_PORT }} --cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: File transfer with SCP
uses: appleboy/scp-action@master
with:
username: ${{ secrets.SSH_USER }}
host: ${{ secrets.SSH_ADDR }}
key: ${{ secrets.SSH_KEY }}
source: algohub.zip
target: /home/ubuntu/algohub-artifact
- name: SSH Commands to deploy
uses: appleboy/[email protected]
with:
username: ${{ secrets.SSH_USER }}
host: ${{ secrets.SSH_ADDR }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.AWS_SSH_PORT }}
script_stop: true
script: |
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
pm2 kill
rm -rf algohub
unzip ./algohub-artifact/algohub.zip/algohub.zip -d ./algohub
cd algohub
pnpm install --frozen-lockfile
pm2 start pnpm --name algohub -- start