Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying GitLab pages for different branches

Tags:

I am deploying my React app using GitLab Pages, and it works well.

Here is my gitlab-ci.yml:

# Using the node alpine image to build the React app image: node:alpine  # Announce the URL as per CRA docs # https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#advanced-configuration variables:   PUBLIC_URL: / # Cache node modules - speeds up future builds cache:   paths:   - client/node_modules  # Name the stages involved in the pipeline stages: - deploy  # Job name for gitlab to recognise this results in assets for Gitlab Pages # https://docs.gitlab.com/ee/user/project/pages/introduction.html#gitlab-pages-requirements pages:   stage: deploy   script:     - cd client     - npm install # Install all dependencies     - npm run build --prod # Build for prod     - cp public/index.html public/404.html # Not necessary, but helps with https://medium.com/@pshrmn/demystifying-single-page-applications-3068d0555d46     - mv public _public # CRA and gitlab pages both use the public folder. Only do this in a build pipeline.     - mv build ../public # Move build files to public dir for Gitlab Pages   artifacts:     paths:     - public # The built files for Gitlab Pages to serve   only:     - master # Only run on master branch 

Now, I just created a dev version, based on my branch develop

I would like to have 2 versions of my React app with 2 different URLs. How can I do that?

For example right now, I have:

my-react-app.com linked to master branch

How should I have

dev.my-react-app.com or even my-react-app.gitlab.io linked to develop branch?

like image 464
Juliatzin Avatar asked Apr 09 '19 15:04

Juliatzin


People also ask

How many GitLab pages can you have?

In general, you are allowed to create and host two sorts of websites with GitLab Pages: User/Group Websites - a single site per user or group. Project Websites - as many sites you want.

Does GitLab have something like GitHub pages?

As you might have guessed, the idea behind GitLab Pages is, like the name, very similar to Github Pages, which provides a space for a more complex static frontpage for projects, and which have been supported as a deployment option in Publii since the early beta releases.

What GitLab feature allows you to publish static websites directly from a repository in GitLab?

Navigate to your project's Settings > CI/CD and click on "Enable shared runners." This combines the power of GitLab CI/CD with GitLab Runner to deploy static sites based on any generator.


1 Answers

I've had success using the browsable artifacts for this purpose. In your example, you would create a job for your develop branch and set the PUBLIC_URL to the path on gitlab.io where the job's artifacts are published:

develop:     artifacts:         paths:           - public      environment:         name: Develop         url: "https://$CI_PROJECT_NAMESPACE.gitlab.io/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html"      script: |         # whatever      stage: deploy      variables:         PUBLIC_URL: "/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public" 

Setting the environment as indicated produces a »Review app« link in relevant merge requests, allowing you to get to the artifacts with a single click.

Note: if your repository is in a subgroup, you need to insert the subgroup name in two places above above between /-/ and $CI_PROJECT_NAME for the resulting URLs to work.

like image 111
joki Avatar answered Sep 16 '22 16:09

joki