Updated: 03 September 2023
CI Pipelines
Static Site
To deploy a static site we make use of the pages object. Our script will make a new public directory and copy our site files to this directory. The only lists the branch from which we want our deployments to run from
Also note that for GitLab Pages Deployments you need to ensure that the deployment arifacts end up in the public directory because Pages cannot deploy from anywhere else
Hence the cp .public, mv .public stuff
1pages:2 stage: deploy3 script:4 - mkdir .public5 - cp -r * .public6 - mv .public public7 artifacts:8 paths:9 - public10 only:11 - masterAngular
We have two stages from our Angular deployment
Build
During our build stage we install our dependencies, do the application build, and expose our distfolder as an artifact which can be passed to our deploy stage
Deploy
We simply copy the contents of our dist folder to our public directory.
Note that we also need to modify our index.html file’s base url to be <base href=""> otherwise our app will get a 404 error when trying to get our script and css files
1build:2 image: node:latest3 stage: build4 script:5 - echo "compile"6 - npm install7 - npm install -g @angular/cli8 - npm run build9 - ls dist10 artifacts:11 paths:12 - dist13 cache:14 paths:15 - node_modules1pages:2 stage: deploy3 script:4 - ls5 - echo "deploy"6 - ls dist7 - mkdir .public8 - cp -r dist/. .public9 - mv .public public10 - ls public11 artifacts:12 paths:13 - public14 only:15 - develop1stages:2 - build3 - deploy4
5build:6 image: node:latest7 stage: build8 script:9 - echo "compile"10 - npm install11 - npm install -g @angular/cli12 - npm run build13 - ls dist14 artifacts:15 paths:16 - dist17 cache:18 paths:19 - node_modules20
21pages:22 stage: deploy23 script:24 - ls25 - echo "deploy"26 - ls dist27 - mkdir .public28 - cp -r dist/. .public29 - mv .public public30 - ls public31 artifacts:32 paths:33 - public34 only:35 - develop1<!doctype html>2<html lang="en">3<head>4 <meta charset="utf-8">5 <title>Nabeel's Blog</title>6 <base href="">7 <meta name="viewport" content="width=device-width, initial-scale=1">8 <link rel="icon" type="image/x-icon" href="favicon.ico">9</head>10<body>11 <app-root class="content"></app-root>12</body>13</html>