packer valiadte 9 #5
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
name: AMI creation | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
ami-creation: | |
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 | |
# - name: Upload Artifact | |
# uses: actions/upload-artifact@v3 | |
# with: | |
# name: installation-scripts | |
# path: | | |
# ./*.sh | |
# 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: Make scripts executable | |
# run: | | |
# chmod +x secure_mysql_installation.sh | |
# chmod +x install_node.sh | |
# chmod +x usergroup.sh | |
# chmod +x nodeapp.sh | |
- name: Copy scripts to /tmp directory | |
run: | | |
cp *.sh /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 |