For flexibility in your content, static websites are preferred. But, when it’s about a static website on a platform like AWS, GitLab is one very helpful tool. This automates the process of deployment. To understand further let’s first know why we need a static website instead of a dynamic website.
Why Do We Need a Static Website?
Companies are using static websites for various reasons.
- Static websites are best for their fewer maintenance fees. Users who don’t want to change their pages often can rely on static websites. They are great for web hosting and CMS. Also, you don’t have to hire any developer to develop your site as it can be done quickly with the help of tools like Jekyll and Hugo.
- Server-side rendering (SSR) is an application that converts HTML files into fully rendered HTML pages on the server. Static websites use this to update the static content after you have built your site. The formatting guidelines that are applied when constructing your document are specified in the structured application.
- Static websites are more efficient than other dynamic websites as they work out everything beforehand due to their content delivery network, optimized design, and caching.
- Static websites interplay greatly with CMS to give flexible, scalable, and secure solutions for both the users and the developers.
Benefits of GitLab CI
CI (Continuous Integration) system tools provide developers and DevOps with the necessary capabilities like source control, artifacts structuring, and deployment.
GitLab brings quite a lot of advantages for CI. It helps in stressless installation to advanced automation processes. This tool is a web-based application that promotes ethical coding practices inside the team and secure production deployment.
Installing GitLab CI tools in your container or on any reminders will help you to arrange the process in Kubernetes. This will reduce the amount as you will try to install the tools on cloud platforms and it will be easy to configure the server.
Source code security
The GitLab platform has a fully distributed version control system platform; after all, many CI platforms already have source control built in. GitLab also gives users complete control over access restrictions and code storage location.
The Auto DevOps feature in GitLab enables apps to be automatically found, developed, tested, deployed, and monitored using a CI/CD pipeline. Everything that developers are thinking about or are doing with automation is included in the feature.
Steps to deploy a Static website to AWS with GitLab CI
- Set up S3 Bucket
1.1. Set up S3
1.2. Go to the S3 management console
1.3. Type any name, eg, yourdomainname.com, and the region. Leave the settings page.
1.5. Move to the properties tab.
1.6. Choose a static website hosting card.
1.8. In the index document field type your root page path+ and add the necessary info in the Error document field.
1.10. Go to the permission tab and click the policy of budget.
1.11. Put the following code snippet in the editor.
- Establishing an IAM User To Upload Files To The S3 Bucket
2.1. Create an IAM user (for accessing and uploading data to the bucket).
2.2. Move to the IAM management console.
2.3. Click the ‘Add user’ to build a new policy with the picked name.
2.4. Next, add the code given below.
2.5. Replace the Resource field with your chosen name (this will let users get the data from your bucket).
2.6. Create a new user.
2.7. ✓ the programmatic access in the section of access type.
2.8. Allocate newly built policies.
2.10. Find two important values of variables there, ‘AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
For convenience, you should remember the key or download the .csv file.
- GitLab CI configuration
Establishing the project’s deployment procedure to the S3 bucket is the next step in Amazon web hosting. This step assumes that GitLab CI is appropriately configured.
3.1. Login into your GitLab account
3.2. Move to the project
3.3. Click on settings and go to CI /CD section.
3.4. Click the button of variables in the drop-down menu.
3.5 Enter the following variables
CDN_DISTRIBUTION_ID (if not, can get it after the creation of CloudFront distribution)
3.6. The steps contain first the use of the image of the latest version for the proper execution of all work as they are read-only templates. The contents include instructions for preparing a docker container
3.7. The next step is to follow the below-mentioned codes to pass the CI/CD process with the given variables.
stages: build, deploy
3.8. Then /node_modules content is cached for later use.
3.9. The received result data is stored in the folder and kept in the directory for a day.
– yarn install
– yarn build
– yarn export
expire_in: 1 day
3.10. For installation of necessary dependencies for the process of deployment use
– apk add –no-cache curl jq python py-pip
– pip install awscli
– eval $(aws ecr get-login –no-include-
3.11. The script parameter helps in changing your S3 bucket and updating CloudFront distribution.
– aws s3 cp build/ s3://$S3_BUCKET_NAME/ –recursive –include “*”
– aws cloudfront create-invalidation –distribution-id $
- CloudFront Origination
The final goal is important as you distribute your website pages through CloudFront. It helps as the static website shares the cached copy of applications stored in different data centers all over the world. The process includes:
4.1. Navigate to the dashboard of CloudFront.
4.2. Press Create Distribution.
4.3. Type the S3 bucket endpoint in the ‘Origin Domain Name’ field (it must be yours).
With auto-completion, your origin ID will be produced automatically.
4.5. Next, type your original Domain Name like www.yourdomainname.com. as you will be having an SSL CloudFront certificate, this your domain name will have .cloudfront.netpapart.
4.6. Outplace your region and then go to Amazon Certification Manager to add the wanted domain name.
4.7. You need to confirm your ownership with the domain name for that go to the setting for DNS and specify your CNAME. When your SSL certificate is produced select “Custom SSL Certificate” in the Distribution Setting option.
In this manner, a fresh CloudFront origin is produced, which is then quickly added to all AWS edge networks. The State field, which shows two states: pending or enabled, can be viewed by going to the dashboard page.
Reach out to our experts and get a consultation regarding GitLab. Visit https://metapercept.com, for more details.