DevOps Training
  • DevOps
  • What is DevOps
    • What DevOps Look like
    • Why DevOps Needed
    • DevOps Automation Tools
    • DevOps Principles
  • cloud computing
    • How DevOps links with Cloud Computing
    • What is cloud computing?
      • Platform as a service (PaaS)
      • Infrastructure as a service (IaaS)
      • Software as a service (SaaS)
      • Function as a Service
      • SaaS, PaaS, IaaS
  • Version Control
    • Git as Version Control
      • Setting up Remote Repo
      • Git Hooks
      • github vs gitlab vs bitbucket
      • Quick Recap Git
  • DevOps #01 Continuous Integration
    • Continuous Integration & Continuous Delivery
      • Understanding CI Tools
      • Prerequisite
      • Continuous Integration
      • CI Tools
      • Travis-CI
        • Travis CI with S3
        • Static Site Build S3
        • Beanstalk with AWS CLI
          • Elastic Beanstalk with Travis CI
        • Travis using Code Deploy EC2
          • Github and Code Deploy
          • Travis CI with Code Deploy
      • Gitlab-CI
        • CI Setup for application
        • Gitlab Runners on EC2
        • CI Integration with AWS
          • Deploying App using Gitlab CI
          • Gitlab CI with AWS S3
          • Gitlab CI with ECS
          • CI Integration with EC2
            • Update and Clean Gitlab.yml
        • Install Gitlab on EC2
      • CI/CD using Jenkins CI
        • Jenkins Build on EC2
        • Jenkins Build EC2 Ubuntu
        • Jenkins CI/CD
          • Create a Build Item
          • Create a Build Pipleine
            • Pipeline Using Docker
            • Pipeline Examples
          • Jenkins CI with S3
            • Jenkins CI - S3
          • Jenkins CI with EC2
    • Jenkins CI Cluster Mode
    • AWS Code Pipeline CI/CD
      • AWS CI/CD Tools
        • AWS Code Build
        • AWS Code Deploy to Beanstalk
        • AWS Code Deploy to EC2
        • AWS Pipeline - Example CI/CD
  • Docker
    • Docker
      • Docker for Developers
        • Install and setup
        • Docker Commands
        • Docker Images Container
        • Docker Architecture
    • Docker Demos
      • Node JS Container
    • Docker-compose
      • Using Docker Compose
      • Docker Compose Demo
  • AWS Quick Refresh
    • AWS Quick Recap - Videos
    • AWS Quick Recap
  • AWS Architecture - Lab
    • Application Deployment - 01
    • Application Deployment - 02
    • Application 3 tier Architecture
  • Basic Networking
    • Computer Networking for Beginners
      • Basic of Networking
      • Networking Protocols
      • OSI Model
      • Network address and Host address
      • Subnetting Type
    • Network Architecture
    • Networking Layers OSI Model
    • Internet protocol
      • CIDR and subnetting
        • Examples
      • AWS VPC Subnets
  • VPC and Networking
    • AWS VPC
    • VPC Demo
      • Bastion Host | Jump Server
  • AWS Components
    • AWS Components In Depth
      • AWS Storage
        • AWS EBS
        • AWS Cloudfront
        • AWS S3
      • AWS Compute
        • ECS
        • AWS VPC
          • VPC Components
        • AWS EC2
        • AWS ELB
          • Application Load balancer
            • Example
        • AWS EC2 Auto Scaling
          • Demo
        • AWS Route 53
        • AWS Lambda Serverless
          • AWS Lambda Serverless Computing
  • Assignments
    • Assignment 01-Node JS app on EC2
    • Assignment 02-Node JS with Mysql
    • Assignment-03
  • Microservices
    • Microservices Architecture
      • Docker and Docker-Compose
      • Docker-Compose Example 01
      • Docker-Compose Example 02
      • Hand-on | Building Microservices
    • Architecture Components
  • AWS ECS
    • AWS ECS
      • Introduction of ECS
Powered by GitBook
On this page

Was this helpful?

  1. DevOps #01 Continuous Integration
  2. Continuous Integration & Continuous Delivery
  3. Gitlab-CI
  4. CI Integration with AWS

Deploying App using Gitlab CI

PreviousCI Integration with AWSNextGitlab CI with AWS S3

Last updated 5 years ago

Was this helpful?

Continuous Integration allows you to:

  • Deploy your app instantly, when new code is pushed into a repo

  • Build your app (in our case npm run build)

  • Trigger test scripts (and block deployment if a test fails)

It is definitely worth the effort if you update your app regularly.

GitLab is a service that started as an open-source GitHub competitor, mostly to host code in Git repositories, and evolved into an amazing tool that I won’t introduce here, as it isn’t related to Vue.js. One thing though, they were one of the first major companies to use Vue.js for their user interface.

Docker has to be mentioned as well. It is the most popular containerization service. It basically means you get to execute code in a secure environment, configured exactly like your dev/prod. Very useful when you need to make sure your code is executed with all its dependencies.

Each of these tools would require many posts to be covered. We’ll focus on setting up CI/CD for your Vue.js project. We’ll assume you have no knowledge in the matter.

, I don’t know any other tool with such a beautiful UI that does that. If you do, please let me know.

The .gitlab-ci.yml file

Create a .gitlab-ci.yml file at the root of your repo. GitLab will check for this file when new code is pushed. If the file is present, it will define a , executed by a . Click the links if you are curious, or keep reading to see a working example.

Default stages of a pipeline are:

  1. build

  2. test

  3. deploy

Again, you don’t need to master this, but this is the most common use case. You may not have set up unit tests, and if you haven’t, you may remove this step from the file, GitLab won’t mind.

Here is our file, you may copy/paste it in your repo:

build site:
  image: node:6
  stage: build
  script:
    - npm install --progress=false
    - npm run build
  artifacts:
    expire_in: 1 week
    paths:
      - dist

unit test:
  image: node:6
  stage: test
  script:
    - npm install --progress=false
    - npm run unit

deploy:
  image: alpine
  stage: deploy
  script:
    - apk add --no-cache rsync openssh
    - mkdir -p ~/.ssh
    - echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa
    - chmod 600 ~/.ssh/id_dsa
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
    - rsync -rav --delete dist/ user@server.com:/your/project/path/

Test our file

Now commit and push the .gitlab-ci.yml file to your GitLab repo.

Here is how it will look in the Pipelines tab of GitLab UI:

The green checkmark indicates that the step has succeeded and you can see the logs when clicking it.

In the second example, the tests have failed, click the red mark to read the logs and understand what went wrong.

File anatomy

  • image is the link to the Docker image. I have chosen to use public official images, but you may use one from the Docker Hub or a private registry.

  • script are command lines executed inside our build environment.

  • artifacts describes a path to the build result. The files in this path can be used in the next build steps (in deploy in our example). You can download artifacts from Gitlab UI.

About the deployment script

To get it working, you’ll need to provide GitLab with a private SSH key. If you are no security expert, then it is time to take advice from one. The bottom line is do not give it your private SSH key, create one that is used only by GitLab.

# create gitlab user
adduser gitlab

# generate a DSA SSH key
su -l gitlab
ssh-keygen -t dsa

# authorize the key to log in using the public key and output the private one
cd .ssh
mv id_dsa.pub authorized_keys
cat id_dsa && rm id_dsa

Then go to GitLab UI “Settings” (the gear icon), then “Variables” and copy/paste the content of your terminal in “Value”. The “Key” should be SSH_PRIVATE_KEY. This private key will be used to do the rsync.

GitLab CI/CD Pipelines
GitLab CI/CD logs

stage should be build, test or deploy if you use defaults. But that .

More about the .gitlab-ci.yml file options .

I have described my use case here, but it may not be the simplest. Relevant examples for or other services can be found online.

GitLab CI/CD variables
GitLab CI/CD is free for personal projects
pipeline
GitLab Runner
can be customized
in the docs
deployment to Amazon S3