Jump toUpdate content
Creating and deploying an Angular application on Serverless Containers
- compute
- serverless
- angular
Angular is a development platform that can scale from single-developer projects to enterprise-level applications. The platform is built on TypeScript, a superset of JavaScript, and provides features such as:
- A component-based framework for building scalable web applications
- A collection of libraries that cover a wide variety of features, including routing, forms management, client-server communication, and more
- A suite of developer tools to develop, build, test, and update code
You may need certain IAM permissions to carry out some actions described on this page. This means:
- you are the Owner of the Scaleway Organization in which the actions will be carried out, or
- you are an IAM user of the Organization, with a policy granting you the necessary permission sets
- You have an account and are logged into the Scaleway console
- You have a Container Registry namespace
- You have installed Angular on your local computer
- You have installed Docker on your local machine to build and push the Docker image
- You have configured your SSH key
Creating a demo application
-
Run the command below to create a new Angular application. It initializes a new project and creates the files required to build the application.
ng new demo-appImportant:Make sure
angular-cli
is installed on your local machine. If you have not installed it yet, runsudo apt install angular-cli
on Ubuntu/Debian Linux based machines or install it using Homebrew on MacOS:brew install angular-cli
. -
Enter the application directory:
cd demo-appRun the command
ls
to see a list of the applications’ files:README.md node_modules src tsconfig.spec.jsonangular.json package-lock.json tsconfig.app.jsonkarma.conf.js package.json tsconfig.json -
Type the following command to run the development server:
ng serve -
Open a web browser and point it to
http://localhost:4200
to see the Angular application:Press
CTRL+C
in your terminal to stop the development server. -
Add a
nginx-configuration.conf
file inside thedemo-app
directory and add the following content to it:# Expires mapmap $sent_http_content_type $expires {default off;text/html epoch;text/css max;application/json max;application/javascript max;~image/ max;}server {listen 80;location / {root /usr/share/nginx/html;index index.html index.htm;try_files $uri $uri/ /index.html =404;}expires $expires;gzip on;}The configuration file above contains information about expiration headers for images and other content (CSS, HTML, etc.) and switches
gzip
compression on to improve the performance of the application. -
Create a Dockerfile named
Dockerfile
in the applications’ directory and copy the following information into it:# Build and compile the frontendFROM node:latest as build-stageWORKDIR /appCOPY package*.json /app/RUN npm installCOPY ./ /app/RUN npm run build -- --output-path=./dist/out --configuration production# Get the compiled app ready to be served with NginxFROM nginx:latestCOPY --from=build-stage /app/dist/out/ /usr/share/nginx/htmlCOPY ./nginx-configuration.conf /etc/nginx/conf.d/default.conf
Building and publishing the Docker image
Make sure that you have connected your namespace to the Docker CLI before running the following steps.
-
Run the following command to build the Docker image:
docker build -t demo-app:latest . -
Tag the Docker image:
docker tag demo-app:latest rg.fr-par.scw.cloud/demo-namespace/demo-app:latestTip:- Make sure you replace
demo-namespace
with the name of your Container Registry namespace. - Make sure that the privacy settings of your namespace are set to public.
- Make sure you replace
-
Push the image to the registry:
docker push rg.fr-par.scw.cloud/demo-namespace/demo-app:latest
Deploying the application on Serverless Containers
-
Click Containers in the Serverless section of the side menu of the Scaleway console. A list of your container namespaces displays.
-
Click the name of the namespace in which you want to deploy the application. The list of your containers displays.
Tip:If you do not have a container namespace yet, click + Create a namespace to create a new one.
-
Click Deploy a Container. The container deployment wizard displays.
Provide the following information to deploy the container:
- Choose the pushed image in your registry’s namespace and set the port value to 80.
- Choose a name and an optional description for the container
- Define the container’s resources
- Configure the scaling of your application
- Leave the other options at their default values
- Choose the pushed image in your registry’s namespace and set the port value to 80.
-
Click Deploy a Container to deploy your application. Your application displays in the list of containers:
-
Click on the container’s name. The container information page displays. Click the Container Settings tab. The container endpoint displays in the container information block.
Copy the endpoint URL and open it in a web browser. The Angular application displays. It can now automatically scale based on the application’s load and within the ranges set for the deployment.