Trouble with Shell Runner and copying my React PWA to the working directory

Edit:

Well, I figured out the permissions issue. I had forgotten to recursively update the permissions down the directory. chmod -R g+rxw <dir>/. whoops
But my second question is still valid. Am I even approaching my deploy to staging in a good way?
I have looked around and read many articles, and the documentation, but this is my first real attempt at CI so thoughts are appreciated.

End Edit

Greetings all,
Right down to it. So I have been struggling with ci-cd for a few months now. But I have almost gotten it to where I want it on my staging server, but I have a small problem. After I build the new production optimized build, I move it from the GitLab-runner’s directory to the directory that will be delivering the site out to the world/staging environment for more testing. This is where it fails. it fails with a permissions error, and I believe the runner has permission to write to the directory, but I would really like to know if I am approaching this in the correct manner. Here is my .gitlab-ci.yml file

`stages:

  • build
  • deploy

build:
stage: build
tags:
- Build PWA
script:
- echo “Building Deploy Package”
- npm install
- npm run build
- echo “Build successful”
artifacts:
expire_in: 1 hour
paths:
- build

deploy_production:
stage: deploy
tags:
- Deploy Staging
script:
- echo “Deploying to server”
- cp -rv /home/gitlab-runner/builds/qRT2eXnz/0/AssemblersInc/developers/fubar /home/root1/example/fubar
- echo “Deployed”
environment:
name: staging
url: https://intradev.assemblers.local
only:
- master
`
Any thoughts or ideas would be greatly appreciated.

I have resolved the issue. Here is what I learned.
The problem after the permissions issue was that I did not understand what the “Artifacts” were.
Artifacts uploaded to GitLab, but what you are actually defining is the folder that you are wanting stored as an artifact
example:
lets say your build npm build is here /home/gitlab-runner/builds/abc123/0///project
Project then has folders and files such as:
folder1
folder2
package.json
gitlab-ci-yml

What you specify as an Artifact is a folder or file inside your build directory

Artifact:
        path:
            - folder1

is actualy /home/gitlab-runner/builds/abc123/0///project/folder1

In my particular case gitlab removes node_modules/ and .next/ from my project so I saved the node_modules as a cache and .next/ as an artifact and put them back into the build when it was time to move to the final served location. I’m attaching my new gitlab-ci.yml in case it helps anyone else.

stages:
  - install_dependencies
  - build
  - deploy

dependencies:
  stage: install_dependencies
  cache:
    key: $CI_COMMIT_REF_SLUG-$CI_PROJECT_DIR
    paths:
      - node_modules/
      - .next/
  script:
    - npm ci
  only:
    changes:
      - package-lock.json

build:
  stage: build
  tags:
    - Build PWA
  cache:
    key: $CI_COMMIT_REF_SLUG-$CI_PROJECT_DIR
    paths:
      - node_modules/
    policy: pull
  script:
    - echo "Building Deploy Package"
    - ls -alh
    - npm run build
    - echo "Build successful"
  artifacts:
    paths:
      - .next/
  only:
    - master


deploy_staging:
  stage: deploy
  tags:
    - Deploy Staging
  cache:
    key: $CI_COMMIT_REF_SLUG-$CI_PROJECT_DIR
    paths:
      - node_modules/
    policy: pull

  script:
    - echo "Deploying to server"
    - rsync -a --delete ../fubar <redacted>
    - echo "Deployed"
  environment:
    name: staging
    url: <redacted>
  only:
    - master

deploy_prod:
  stage: deploy
  tags:
    - stable deploy_prod
  script:
    - echo "deploying to production"
    - ls -alh
    - npm ci
    - npm run build
    - rsync -a --delete ../fubar <redacted>
    - echo "deploy to production complete
  environment:
    name: production
    url: <redacted>
  when: manual
  allow_failure: false
  only:
    - stable