Clone the project
git clone https://github.com/Viorel1989/fastify-hello-world.git
Go to the project directory
cd fastify-hello-world
Run npm install to install required depdendencies
npm install
Start server
npm start
Requests sent to localhost:3000 will respond with the following json:
{
"hello": "world"
}
To run tests, run the following command
npm run test:unit
Before you start, make sure you have the following installed on your machine:
- Python (to use pip)
pip install pre-commit
pre-commit install --hook-type commit-msg
Create resource group
az group create -n fastifyResourceGroup --location westeurope
Create service principal
# !!! Save the content of $AZURE_SECRETS in safe place for long-term storage
AZURE_SECRETS=$(az ad sp create-for-rbac -n "$USER@$(hostname -f)" --role Contributor --scopes /subscriptions/$(az account show --query "{ subscription_id: id }" | jq -r ".subscription_id") --query "{ client_id: appId, client_secret: password, tenant_id: tenant }")
Build image
packer init fastifyVM.pkr.hcl
packer build \
-var "subscription_id=$(az account show --query "{ subscription_id: id }" | jq -r ".subscription_id")" \
-var "tenant_id=$(echo $AZURE_SECRETS | jq -r ".tenant_id")" \
-var "client_id=$(echo $AZURE_SECRETS | jq -r ".client_id")" \
-var "client_secret=$(echo $AZURE_SECRETS | jq -r ".client_secret")" \
-var "version=sha-$(git rev-parse --short HEAD)" \
fastifyVM.pkr.hcl
Create VM
az vm create \
--resource-group fastifyResourceGroup \
--name fastify-hello-world \
--image fastifyVM-sha-$(git rev-parse --short HEAD) \
--size Standard_B2ats_v2 \
--admin-username $USER \
--ssh-key-values ~/.ssh/id_ed25519.pub
az vm open-port \
--resource-group fastifyResourceGroup \
--name fastify-hello-world \
--port 3000
curl $(az vm list-ip-addresses --name fastify-hello-world --resource-group fastifyResourceGroup --query "[0].virtualMachine.network.publicIpAddresses[0].ipAddress" | jq -r):3000
az resource delete --ids $(az resource list -g fastifyResourceGroup --query "[].id" -o tsv)
- Installed Commitizen as pre-commit hook to ensure Semantic Versioning and Conventional Commits specifications
- Added editorconfig, prettier and eslint for formatting consistentcy
- (VS Code only) Install VS Code extensions: ESLint, Prettier ESLint and EditorConfig.