IBM project is my solution to a technical assignment provided to me in the second stage of the recruitment process to IBM. This assignment required me to deploy a web page which would show how many unique visitors have visited the page.
Azure Redis Cache resource can take 15-40 minutes to deploy, please give the pipeline up to 40 minutes to deploy. If terraform apply step is running, means its working. In addition to that, the image can take some time to be pulled into the Azure App Service. If website does not load, refresh couple of times to see the
It is important to note that this pipeline also deploys remote state for terraform. This state is stored in storage accounts and storage containters which need to have unique global names. I have generated a random string variable for these names in deploy_infra.yml. If you want to deploy multiple instances of this infrastrucutre then you need to change these values.
Another imortant note is the the DNS of the app. It is created using resource name set by terraform. If you want to deploy multpiple instances of infra, you have to change RESROUCES_PREFIX: "IBM-PROJECT" env var to something else. Otherwise the terraform will crash.
My solution was to deploy the app to Azure Cloud using Github Actions
-
DEPLOY_INFRASTRUCTURE (.github/workflows/deploy_infra.yml) - This pipeline builds and pushes the image into image registry, deploys backend state for terraform if not found and deploys the infrastructure with the app.
-
DEPLOY_APP (.github/workflows/deploy_app.yml) -This pipeline assumes that the infrastructure is already deployed. When app changes are pushed into the "deploy_app" branch, the pipeline builds the image, pushes it into the registry and deploys the app into the existing infrastructure.
-
DESTROY_INFRASTRUCTURE (.github/workflows/destroy_infra.yml) - This pipeline destroys the infrastructure and backend state if specified in input.
The web app is a simple Next.js app which stores the unique visitors value in Redis.
-
Image tag - displays the current version/tag of the image. This tag injected during Dockerfile build and is taken from ./my-app/VERSION file. By incremeting this tag in VERSION file and pushing it to repo it is easy to test if the pipeline has sucessfully deployed the new version of the app.
-
Unique visitors - displays the number of unique visitors. This value is stored in Redis and is incremented every time a new user visits the page.
Redis is used to store the unique visitors value. The Redis is deployed as a Azure Cache for Redis service in a seperate resource.
-
Terraform passess variables to the Azure App Service instace which injects them to the environment.
-
Server-side code pulls these variables from the environment and connects to the Redis.
Terraform code is split into 2 modules: redis_cache and web_app
├── main.tf
├── modules
│ ├── redis_cache
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ └── web_app
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
├── outputs.tf
├── providers.tf
├── terraform.tfvars
└── variables.tfThere are 2 ways to use this repo: you can test the deployment here using manual workflow dispatch or you can fork the repo and use the pipelines yourself with your own secrets.
This repo was made in a way that you can deploy the app without any additional modifications.
The infrastructure is deployed on my personal Azure account. To do so:
- Go to Actions
- Select the workflow you want to run. (Use "Deploy infrastructure" first to deploy infra)
- Click "Run workflow" and fill in the variables if needed.
The app will deploy and you will be able to access it through the link provided in the terraform output. Or you can go straight to https://ibm-project-webapp.azurewebsites.net
This repo is configured to deploy the app to my Azure account. If you want to test it yourself, you can fork the repo and add the needed secrets (see below). Other that that, there are no additional changes needed.
If you want to fork the repo and use the pipelines yourself, you will have to add these secrets:
-
AZURE_CLIENT_ID - for Azure access
-
AZURE_CLIENT_SECRET - for Azure access
-
AZURE_SUBSCRIPTION_ID - for Azure access
-
AZURE_TENANT_ID - for Azure access
-
IBM_REPO_TOKEN - token for your ghcr.io image repository with read and write permissions





