Skip to content
Snippets Groups Projects
Commit f3a002dd authored by Simon Törnqvist's avatar Simon Törnqvist
Browse files

add gitlab build+deploy pipeline

parent cc4cd7dc
No related branches found
No related tags found
No related merge requests found
# Define the stages of this pipeline. Each job is associated with a stage.
# Multiple jobs may be run in parallell during a stage. Dependant jobs
# should run in different stages.
stages:
- build
- deploy
# Define a pipeline job for building the app
build-job:
image: node:18 # Run this job in a docker image with node 18 installed
stage: build
script:
- cd app/
- npm install --production # Install nodejs production dependencies, skipping unnecessary
# development dependencies
- npm run build # Build the app. Results stored in build/
artifacts:
paths:
- app/build/ # Save the build results for upcoming jobs
# Define a pipeline job for deploying the build results. Must be named
# "pages" to deploy to GitLab pages
pages:
stage: deploy
script:
- export target="public/" # Location used by GitLab CI/CD
- mkdir $target
- cp -r app/build/* $target # Copy build results into target dir
artifacts:
paths:
- public # Save target dir
...@@ -37,4 +37,9 @@ then run ...@@ -37,4 +37,9 @@ then run
npm run build npm run build
```` ````
This should create the directory ```build```, containing the file ```index.html```. This file is the entry point for your web application. Depending on your environment (operating system, browser, etc), this file might be able to be opened by your browser. This should create the directory ```build```, containing the file ```index.html```. This file is the entry point for your web application. Depending on your environment (operating system, browser, etc), this file might be able to be opened by your browser.
\ No newline at end of file
# Deployment
The file ```.gitlab-ci.yml``` is used by GitLab to create [CI/CD jobs](https://docs.gitlab.com/ee/ci/). This can be used to build, test and deploy your app. The current ```.gitlab-ci.yml``` file is set to build and deploy the app when you push to any branch. The latest pipeline can be found on ```project/-/pipelines/latest``` (for example https://gitlab.liu.se/simto05/react-proof-of-concept/-/pipelines/latest). The deployed page can for this instance be found on https://simto05.gitlab-pages.liu.se/react-proof-of-concept/.
A slight modification was made to the file ```package.json``` in directory ```app/``` because of GitLab CORS policy: the key ```homepage``` was set to "." to inform ```create-react-app``` that static files are located relative to the ```index.html``` file. This modification should work for most servers, but may vary with different setups.
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"name": "app", "name": "app",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"homepage": ".",
"dependencies": { "dependencies": {
"@testing-library/jest-dom": "^5.17.0", "@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^13.4.0",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment