- Framework: Angular 10
- CI: GitLab pipelines
- CD: GitLab pipelines + AWS S3 + CloudFront
This project requires:
- node 14.x
- npm 6.x
To install node, it is highly recommended to use Node Version Manager, NVM. You can install it the following way:
# Install NVM. Check their repository for the latest version.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
# Source .bashrc so we can use the nvm command.
source ~/.bashrc
# Install node version 14. This will also install npm version 6.
nvm install 14
When you work on this project, make sure you are using the right version of node.
# Use node version 14.
nvm use 14
# Verify the versions with the following commands.
node -v
npm -v
If you don't want to use NVM, you can install node the following way.
# Install node without NVM.
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt-get install -y nodejs
-
Clone this repo and change directory into it:
git clone https://github.com/gazebo-web/gazebosim-frontend.git cd app
-
Install dependencies
npm install
Use the develop
branch for development. Merge requests should target it. The master
branch is only used for Production releases.
Before serving the app for development or building it for deploy, you need to set the environment variables to use. This repository comes up with an example setup.bash file which works with the Staging API.
source ./setup.bash
You can serve the app locally with the following command.
npm start
The app uses port 3000 by default. If you want to use a different one, you can serve it with the Angular CLI command.
ng serve --port <port>
The app can be built for different environments with the following commands. The different environments are listed in the angular.json file, each one having different options and optimization levels. Remember to provide the environment variables to use.
# Development
npm run build
# Staging
npm run build:staging
# Production
npm run build:prod
The output can be found in the dist/app
folder.
-
Run tests
npm run test
The generated coverage can be found in
./coverage/html/index.html
. -
Run the linter
npm run lint
The staging
branch in this repository is used to deploy this website to
https://staging-app.gazebosim.org. The production
branch in this repository is
used to deploy this website to https://app.gazebosim.org
.
Github actions will automatically deploy staging
on push. The production
branch will only deploy when an authorized user approves the deployment on
the Github Actions UI.
There is no rule about how a release should be made. A person with sufficient access can choose between direct commits or pull requests.
Though the preferred way to deploy is through pipelines, sometimes you need to deploy the app manually. Here is a list of steps required to do so.
First, you need the AWS CLI installed and configured. You can do it the following way.
# Install
sudo apt install python-pip
pip install --upgrade --user awscli
# Configure
aws configure
-
Provide the environment variables and build the app for the desired environment, as mentioned in the previous section.
-
Enable preview stage (for Cloudfront support).
aws configure set preview.cloudfront true
-
Sync the build output to the corresponding S3 bucket.
Where
APPLICATION_ENVIRONMENT
can be-
Integration:
integration-app.gazebosim.org
-
Staging:
staging-app.gazebosim.org
-
Production:
app.gazebosim.org
aws s3 sync dist/app s3://$APPLICATION_ENVIRONMENT
-
-
Trigger an invalidation in Cloudfront.
aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths '/*'
Make sure you are using the
CLOUDFRONT_DISTRIBUTION_ID
of the environment you deployed.
You can select a specific spec our suite to run by using fdescribe()
or fit()
. In a similar way, you can skip tests with xdescribe()
or xit()
. Read Jasmine documentation for more information regarding tests.
Each component and service being test requires a TestBed, which needs to be configured before each spec method. If the component has an external layout (separate html
and css
files), it requires to be compiled. We are doing this through Webpack in the Karma test configuration, thus there is no need to call the TestBed method to compile the component.
Following the Angular Style Guide, we use the gz
prefix for the selector of our Components and Directives. This is configured in the linter.
Variables referenced in HTML templates must be public
. Private variables inside a component.ts
file cannot be accessed in component.html
nor component.spec.ts
files.
In order to add new environment variables, you need to add them in the custom-webpack.config.js file, so it can be included once the application is built. After, it is advisable to include the new variable inside the environment files, with a fallback value.
To work with environment variables inside the code, you need to include them.
import { environment } from 'src/environments/environment';
Then, you can use it. For example:
const api = environment.API_HOST;