Cannot Mount .env File in Cloud Run #524
-
Hi there! I have try to mount an .env file as secret volume into Cloud Run service (GCP) but it false. Here's what I have try so far:
I try the step 2 and I get 500 server error. I get the log message:
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: laravel-webapp
annotations:
run.googleapis.com/minScale: '1'
spec:
template:
metadata:
name: laravel-webapp-$CI_COMMIT_SHORT_SHA
annotations:
run.googleapis.com/cloudsql-instances: $CLOUDSQL_INSTANCES
run.googleapis.com/network-interfaces: '[{"network": "default", "subnetwork": "default"}]'
run.googleapis.com/vpc-access-egress: 'private-ranges-only'
spec:
serviceAccountName: deployer-cloudrun@<project-id>.iam.gserviceaccount.com
containers:
- name: laravel-webapp
image: $REGION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE_NAME:$CI_COMMIT_SHORT_SHA
env:
- name: APP_NAME
value: Laravel
- name: LOG_STACK
value: stderr
- name: LOG_STDERR_FORMATTER
value: "Monolog\\Formatter\\GoogleCloudLoggingFormatter"
volumeMounts:
- name: env-file
# Mount the secret as /.env
- mountPath: /var/www/html/.env
+ mountPath: /var/www/html
volumes:
- name: env-file
secret:
secretName: laravel-secret
items:
- key: latest
path: .env I try the step 2 and I get File not found.
I try the step 4 and IT WORKS! Then, I take a short conclusion that the serversideup/docker-php cannot read the .env fle that mounted from Cloud Run. Here's my Dockerfile to build the docker image for Laravel project in Cloud Run.
I'm curious, is that possible to mount .env file for laravel project in Cloud Run by using serversideup/php? If it's possible then what's should I change in my Dockerfile? If it's not possible then why? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I've never used Cloud Run before, but I wonder if it is mounting the ENV file as You might have to dive into the docs and see if they support setting the ENV file to a different user |
Beta Was this translation helpful? Give feedback.
I've never used Cloud Run before, but I wonder if it is mounting the ENV file as
root
with600
permissions and our default user ofwww-data
does not have access to it?You might have to dive into the docs and see if they support setting the ENV file to a different user