I am trying to migrate from Go 1.9 to Go 1.11. I am using cloudbuild.yaml to get dependencies and deploy the application. However, I am getting this error:
Failed to build app: Your app is not on your GOPATH, please move it there and try again.
I checked the migration document, and it says I need to put the application into the GOPATH. However, I am not sure if that's possible with cloudbuild.yaml. If yes, could someone share an example?
A simplified version of my cloudbuild.yaml. As far as I know the application source code is under /workspace in this situation. I have tried to include /workspace in GOPATH in the deploy step but no luck.
steps:
- name: 'gcr.io/cloud-builders/go'
args: ['get', 'github.com/go-sql-driver/mysql']
env: ['GOPATH=go']
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy', 'go/src/batch.yaml']
env: ['GOPATH=go']
File structure:
/repo
|-go
|-src
|-batch.yaml
|cronjob.go
Related
I am trying to set up a GitHub action to automatically deploy to Google App Engine when I push to the master branch. However, I am quite new in the pipelines. I tried to do my homework and I ended up stuck with this.
First, this is my .github/workflows/main.yml:
name: Deployment
on:
push:
branches:
- master
jobs:
deploy:
name: Deploy to App Engine
runs-on: ubuntu-latest
steps:
- name: Google App Engine
uses: google-github-actions/deploy-appengine#v0.4.0
with:
project_id: my-gae-project-id
version: master
credentials: ${{secrets.GOOGLE_APP_ENGINE_KEY}}
flags: --no-cache
deliverables: app.yaml
Now I tried to create the app.yaml in the root directory and also in the .github/workflows directory. None of them works. For now, my app.yaml is just:
runtime: php74
env: standard
Here is the outcome of my GH action everytime:
I tried to do some research and found recommendation to put the app.yaml in a folder, so I also tried .github/workflows/gae/app.yaml and then set it as deliverables: gae/app.yaml - no success. Also tried to put the path in quotes like deliverables: "gae/app.yaml" - no success. Also tried to put the app.yaml to the root and set it as deliverables: ../../app.yaml. In some cases, the app.yaml creates a new GitHub action which is even more irritating.
Now I'm just getting frustrated, because I know this is going to be something silly, but I didn't find many resources about this specific case.
There is a missing step in your main.yml that's why your workflow can't find and access the files. To fix it, add checkout#v2 action in your steps:
name: Deployment
on:
push:
branches:
- master
jobs:
deploy:
name: Deploy to App Engine
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Google App Engine
uses: google-github-actions/deploy-appengine#v0.4.0
with:
project_id: my-gae-project-id
version: master
credentials: ${{secrets.GOOGLE_APP_ENGINE_KEY}}
flags: --no-cache
deliverables: app.yaml
You can also visit this official github example for your reference.
I'm new to google cloud and I'm trying my best to implement CI / CD on a simple MERN stack application.
I was able to set up google cloud build and get the deploy with automatic triggers (from github branch) to work.
I have only one question: in the cloudbuild.yaml file I have inserted several steps, to do first npm install, then npm build and finally deploy. The process is quite slow and it also copies all the code to the server, not just the build folder.
I would like to understand how to configure the file to be able to use the build folder already present in the github repository and do the deploy directly, without further steps.
On the frontend I use react, the only thing I have to do is serve the static index.html file.
Here is my current configuration (only the frontend, to understand)
steps:
# Step 0: FRONTEND npm install
- name: "gcr.io/cloud-builders/npm"
dir: 'frontend'
args: ['install']
timeout: "5m"
# Step 1: FRONTEND optimized build
- name: "gcr.io/cloud-builders/npm"
dir: 'frontend'
args: ["run", "build"]
timeout: "5m"
# Step 2: FRONTEND Deploy cloud app frontend
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy", "-v", "0-1-2", "app.yaml"]
dir: 'frontend'
timeout: "20m"
timeout: 60m
In my remote repository I have the build folder ready to use, but I can't figure out how to do the job.
I've also tried something similar to this:
Upload build folder in Google Cloud Build
without success.
One of the problems is that at the end of the process it appears that cloud build is trying to start npm start.
Finally, I am currently using express to simply serve static files.
Using google cloud can I avoid using it and simply configure the handlers from the app.yaml file?
What web server does it use under the hood to serve files if I don't implement express?
If you only need to deploy the build folder, then the link you've provided should do the job. You don't need to run npm install and npm run build unless you want to to copy all your code and create the build folder using Cloud Build.
Credits to #Guillaume (updated, assuming the .yaml file is located at the root directory of the project and build located at a directory called frontend):
steps:
# Step 0: FRONTEND copy only build and deploy cloud app frontend
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: bash
dir: 'frontend'
args:
- '-c'
- |
cd ..
cp app-production-build.yaml frontend/build
cd frontend/build
gcloud app deploy
timeout: '1600s'
By default, Cloud Build uses a directory named /workspace as a working directory. If you set the dir field in the build step, the working directory is set to /workspace/<dir>. Basically for this build step, Cloud Build's currently on a directory called frontend in the root directory of your project/repo.
Also as Guillaume mentioned, you need to update your app.yaml URL handlers for this to work. I tested this sample inside the build folder of a new React app and it works for me:
runtime: nodejs12
service: frontend-react
handlers:
# Serve all static files with url ending with a file extension
- url: /(.*\..+)$
static_files: \1
upload: (.*\..+)$
# Catch all handler to index.html
- url: /.*
static_files: index.html
upload: index.html
To answer your last question, you can serve static files directly from your app and what you need to do is to configure URL handlers such as static_dir or static_files.
Take note that each file inside build/static are cached to speed up performance so there could be a delay whenever you make several deployments.
Node.js on App Engine Standard doesn't use any webserver under the hood and you have to set it up by specifying it on your package.json. Here's some web frameworks recommended by Google docs.
I am experiencing a strange issue with dependencies when deploying my application to Google App Engine (Python 2.7).
I have specified my dependencies in the requirements.txt file:
Flask==1.0.2
werkzeug>=0.14
flask-cors
twilio
httplib2
gunicorn
Jinja2
google-cloud-ndb
exponent_server_sdk
These work fine with the local development server when installed locally with pip from the requirements.txt folder.
However, when I deploy to app engine, it appears that the module exponent_server_sdk has not been installed (ImportError: No module named exponent_server_sdk).
I normally deploy by pushing to a git repository which is then deployed with Google Cloud Build ("gcr.io/cloud-builders/gcloud"). There are no errors when I deploy and other dependencies in the requirements.txt file work fine such as twilio or Jinja2.
Whilst investigating this I tried pushing directly from my development machine with gcloud app deploy. When I do this, for some strange reason, exponent_server_sdk is available and works correctly.
This behaviour seems very strange to me and I can't find any documentation of people experiencing similar errors. I wonder if anyone can give me any guidance about what might be causing this issue or places I can look to find errors (for example logs of the process of installing the requirements.txt file during deployment/instance startup).
In response to the comments:
I am running in the standard environment.
My cloudbuild.yaml looks like this:
steps:
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy", "app.yaml", "dispatch.yaml", "service_1.yaml", "service_2.yaml", "service_3.yaml", "index.yaml"]
timeout: "1600s"
The .yaml file for the service in which I am experiencing the error looks like this:
runtime: python27
api_version: 1
threadsafe: true
service: notifications
libraries:
- name: ssl
version: latest
handlers:
- url: /.*
script: notifications.app
For the (1st gen) standard environment the deployment process does not use a requirements.txt file, the libraries should be installed inside your app. From Copying a third-party library:
Use pip (version 6 or later) with the -t <directory> flag to
copy the libraries into the folder you created in the previous step.
For example:
pip install -t lib/ <library_name>
Yes, if you want you can use a requirements.txt file to do the installation inside your app, but that file itself is not used by the deployment process.
Since you're not deploying directly from the environment in which you had the libraries installed you'd have to add the installation directory to the git repo as well.
I am trying to implement CI/CD functionality using cloud build I have repository available on github. I have integrated my github repository with cloud source repository.Now after creating build triggers when I am running it is showing error:
ERROR: (gcloud.app.deploy) There is a cloudbuild.yaml in the current directory, and the runtime field in /workspace/app.yaml is currently set to [runtime: nodejs]. To use your cloudbuild.yaml to build a custom runtime, set the runtime field to [runtime: custom]. To continue using the [nodejs] runtime, please remove the cloudbuild.yaml from this directory.
Here is my cloudbuild.yaml file:
steps:
#Install
- name: 'gcr.io/cloud-builders/git'
args: ['clone', 'https://github.com/GoogleCloudPlatform/cloud-builders']
#Deploy
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy']
app.yaml
env: flex
runtime: nodejs
Someone please let me know what I am missing or doing wrong.Any help would be appreciated.
THANKS
Try moving all project files including the app.yaml into a subdirectory except couldbuild.yaml and specify the subdirectory containing them in the couldbuild.yaml :
#Deploy
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy', '[SUBDIRECTORY/app.yaml]']
Cloud build builds a Docker file that already specifies the runtime, so you won't have to re-specify it again in app.yaml. It's perfectly fine to change the runtime in app.yaml to custom.
As I understand it, gcloud app deploy triggers a Cloud Build job behind the scenes based on command line options and things like requirements.txt (for python runtime). What I am looking to do is extend these Cloud Build steps to include things like database migration and testing before the deploy.
I can see that I could run these extra steps within separate containers in a separate GCP project, and then as the final step do something like
- name: 'gcr.io/cloud-builders/gcloud'
args: [ 'app', 'deploy', 'app.yaml', '--project', 'my-gae-project', '--version', 'staging' ]
Does that seem like a good way to do it? Has anyone done this kind of thing before for a GAE project?
Check out the instructions for Building, Testing, and Deploying artifacts using Cloud Build. There is a section under "deploying artifacts" that is specific to App Engine and how you would set up your custom build to deploy to GAE.