Simple REST API with Fastify web framework.
Semantic Versioning and Conventional Commits specifications are enforced in this repository.
main
branch is protected and changes must be merged via pull requests.
Clone the project.
git clone [email protected]:altcatalin/fastify-hello-world.git
Go to the project directory.
cd fastify-hello-world
Install pre-commit. Check pre-commit documentation for other options.
pip install pre-commit
pre-commit --version
Set up the git hook scripts.
pre-commit install
Install dependencies
npm install
(VS Code only) Install VS Code extensions: ESLint, Prettier ESLint and EditorConfig.
Run unit tests
npm run test
Start web server
npm run server
Create resource group
az group create -n fastify-hello-world --location germanywestcentral
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 image.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)" \
image.pkr.hcl
Create VM
az vm create \
--resource-group fastify-hello-world \
--name fastify-hello-world \
--image fastify-hello-world-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 fastify-hello-world \
--name fastify-hello-world \
--port 3000
curl $(az vm list-ip-addresses --name fastify-hello-world --resource-group fastify-hello-world --query "[0].virtualMachine.network.publicIpAddresses[0].ipAddress" | jq -r):3000
az resource delete --ids $(az resource list -g fastify-hello-world --query "[].id" -o tsv)