Skip to content

port change

port change #16

name: AMI creation
on:
push:
branches:
- main
jobs:
ami-creation:
if: github.repository == 'csye6225-ramaraju/webapp' # action exec only if code is pushed to org repo main branch
name: build packer ami
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Configure MySQL
run: |
sudo apt-get update
sudo apt-get install -y mysql-server
sudo systemctl start mysql
sudo systemctl status mysql
sudo mysql --user=root --password=root -e "CREATE DATABASE IF NOT EXISTS restapi;"
sudo mysql --user=root --password=root -e "SHOW DATABASES;"
sudo mysql --user=root --password=root -e "USE restapi; CREATE TABLE IF NOT EXISTS Users (id CHAR(36) BINARY PRIMARY KEY, firstName VARCHAR(255) NOT NULL, lastName VARCHAR(255) NOT NULL, userName VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, createdAt DATETIME NOT NULL, updatedAt DATETIME NOT NULL);"
# Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
# Install Dependencies
- name: Install Dependencies
run: npm install
# Run Integration Tests
- name: Run Integration Tests
run: npm test user.test.js
# delete node modules before zipping
- name : delete node modules
run: rm -rf node_modules
# Create Artifact
- name: Create Artifact
run: zip -r application.zip ./*
# Upload the Artifact
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: application-artifact
path: application.zip
# Setup Google Cloud
- name: Setup Google Cloud
uses: google-github-actions/setup-gcloud@v0.2.0
with:
service_account_key: ${{ secrets.GCP_SA_KEY }}
project_id: ${{ secrets.GCP_PROJECT_ID }}
export_default_credentials: true
# Setup Packer
- name: Setup Packer
uses: hashicorp/setup-packer@main
with:
packer-version: 'latest'
- name: List files in the root and /tmp directory
run: |
ls -lah
ls -lah /tmp
- name: List files in the /tmp directory
run: |
ls -lah /tmp
# Build Machine Image with Packer
- name: Build Machine Image with Packer
run: |
packer init .
ls -lah /tmp
packer build -var 'project_id=${{ secrets.GCP_PROJECT_ID }}' webapp-packer.pkr.hcl