Monday, 21 December 2020

REACT APP not access the google cloud run environment variables

i am using GitLab ci as my CI/CD tool. I am deploying the dockrized react app to cloud run but I am not able to access the environment variables declared on cloud run. Thank you!

Dockerfile

# build environment
FROM node:8-alpine as react-build

WORKDIR /app
COPY . ./

RUN npm install
RUN npm run build

# server environment
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/configfile.template

COPY --from=react-build /app/build /usr/share/nginx/html

ENV PORT 8080
ENV HOST 0.0.0.0
EXPOSE 8080
CMD sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"

gitlab-ci.yml

default:
  image: google/cloud-sdk:alpine
  before_script:
    - gcloud config set project PROJECTID
    - gcloud auth activate-service-account --key-file $GCP_SERVICE_CREDS
stages:
  - staging
  - production

staging:
  stage: staging
  environment:
    name: staging
  only:
    variables:
      - $DEPLOY_ENV == "staging"
  script:
    - gcloud builds submit --tag gcr.io/PROJECTID/REPOSITORY
    - gcloud run deploy REPOSITORY --image gcr.io/PROJECTID/REPOSITORY --platform managed --region us-central1 --allow-unauthenticated 

production:
  stage: production
  environment:
    name: production
  only:
    variables:
      - $DEPLOY_ENV == "production"
  script:
    - gcloud builds submit --tag gcr.io/PROJECTID/REPOSITORY
    - gcloud run deploy REPOSITORY --image gcr.io/PROJECTID/REPOSITORY --platform managed --region us-central1 --allow-unauthenticated --set-env-vars NODE_ENV=production


from REACT APP not access the google cloud run environment variables

No comments:

Post a Comment