Deploy Google Cloud Function through Google Build error - unable to prepare context: unable to evaluate symlinks in Dockerfile path - google-cloud-functions

I am unable to deploy a cloud function through google cloud build, receiving the error:
BUILD
Already have image (with digest): gcr.io/cloud-builders/docker
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /workspace/Dockerfile: no such file or directory
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1
My git repo structure is
myrepo/cloudbuild.yaml
myrepo/new-user/index.js
myrepo/new-user/package.json
And my cloudbuild.yaml is as follows
steps:
- name: 'gcr.io/cloud-builders/gcloud'
id: 'newUser'
args: ['functions',
'deploy',
'newUser',
'--source=./new-user/.',
'--trigger-event=providers/cloud.firestore/eventTypes/document.create',
'--trigger-resource=projects/myproject/databases/default/documents/userLocations/{user}',
'--runtime=nodejs8']
I thought for cloud functions, only the cloudbuild.yaml is required, which is why the Dockerfile error is confusing.
Running the following on the command line works fine.
gcloud functions deploy newUser --runtime=nodejs8 --trigger-event=providers/cloud.firestore/eventTypes/document.create --trigger-resource=projects/myproject/databases/default/documents/userLocations/{user} --source=./new-user/.
Thanks.

Your repository has no Dockerfile, so you cannot use a non-existent Dockerfile to build.
Since you are trying to make a serverless container that needs a Docker image as input.

As I just ran into this, the problem for me was linked to the fact that I was working in a monorepo and had to redefine the workspace location Cloud Build would use to find the Dockerfile by adding a dir to my cloudbuild file.
My Cloud Build trigger was setup to look for a cloudbuild file that was located under: <root>/apps/<subfolder>/cloudbuild.yaml
The cloudbuild file was properly picked up by CloudBuild, the build would start but then errored as the Dockerfile was not found.
YAML example:
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'us-west2-docker.pkg.dev/$PROJECT_ID/quickstart-docker-repo/quickstart-image:tag1', '.' ]
images:
- 'us-west2-docker.pkg.dev/$PROJECT_ID/quickstart-docker-repo/quickstart-image:tag1'
- dir: 'apps/<subfolder>'
Reference: Docs

Related

Using PDF2Image in Code Repository on Palantir Foundry

I am trying to use the library pdf2image in a Code Repository on Palantir Foundry and getting the error
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
when using the function convert_from_bytes.
Does anyone know how to reference the poppler path and get rid of this error?
Thanks!
Here is the code:
def extract_pdf_text(input_bytes, language='eng', dpi=200):
pages = convert_from_bytes(input_bytes, dpi)
pdf_pages = ''
for page_index, page in enumerate(pages):
pdf_page = pytesseract.image_to_string(page, lang=language)
pdf_pages = pdf_pages + pdf_page
return pdf_pages
And the meta.yaml for reference:
# If you need to modify the runtime requirements for your package,
# update the 'requirements.run' section in this file
package:
name: "{{ PACKAGE_NAME }}"
version: "{{ PACKAGE_VERSION }}"
source:
path: ../src
requirements:
# Tools required to build the package. These packages are run on the build system and include
# things such as revision control systems (Git, SVN) make tools (GNU make, Autotool, CMake) and
# compilers (real cross, pseudo-cross, or native when not cross-compiling), and any source pre-processors.
# https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html#build
build:
- python 3.8.*
- setuptools
# Packages required to run the package. These are the dependencies that are installed automatically
# whenever the package is installed.
# https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html#run
run:
- python 3.8.*
- transforms {{ PYTHON_TRANSFORMS_VERSION }}
- transforms-expectations
- transforms-verbs
- pytesseract
- pdfplumber
- googletrans
- regex
- pdf2image
- langdetect
- pandas
- numpy
- selenium
- requests
- pypdf2
- poppler
build:
script: python setup.py install --single-version-externally-managed --record=record.txt
I found the problem when inspecting the CI-Checks. They failed before poppler was pulled. After I cleaned up meta.yaml and the checks succeded everything seems to work fine.

Deploy Flask Application using python 3.7

I follow this guideline to deploy my python application.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html
I got this bug when use command eb deploy:
2021/09/10 17:26:49.653297 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2021/09/10 17:26:49.653315 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2021/09/10 17:26:49.656613 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2021/09/10 17:26:49.657975 [ERROR] An error occurred during execution of command [app-deploy] - [StageApplication]. Stop running the command. Error: chown /var/app/staging/env/lib/python3.7/collections: no such file or directory
2021/09/10 17:26:49.657984 [INFO] Executing cleanup logic
2021/09/10 17:26:49.658080 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1631294809,"severity":"ERROR"}]}]}
its so annoy because it can not find python 3.7 to run. can anyone give me a hand to by pass this mess?
application.py
# app.py
from flask import Flask
application = Flask(__name__)
#application.route("/")
def hello():
return "Hello World!"
if __name__ == '__main__':
application.run()
requirements.txt
click==7.1.2
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
Werkzeug==1.0.1
This happened to me while following the tutorial as well.
The problem, in my case, was that my virtual environment folder venv was getting swept up in the deploy and breaking it.
I thought that I could put the path in .ebignore to prevent this, but I did not read the .ebignore documentation clearly:
If .ebignore isn't present, but .gitignore is, the EB CLI ignores files specified in .gitignore. If .ebignore is present, the EB CLI doesn't read .gitignore.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-ebignore
In my case, I just removed the .ebignore file completely, added a line for venv into my .gitignore file, ran eb deploy again and everything worked.

Pipeline fails when running Packer fix

I'm trying to run Packer (1.7) in an Azure DevOps pipeline.
The pkr.hcl files passes validation on my PC running Packer 1.7.3. The pipeline runs Packer 1.7.2.
The YAML task in the pipeline reads like this:
- task: PackerBuild#1
inputs:
templateType: 'custom'
customTemplateLocation: 'ComboBoxes.pkr.hcl'
imageUri: 'ssi-dev-combobox'
imageId: <full resource ID>
When run in the pipeline it reads:
Current installed packer version is 1.7.2.
Running packer fix command
/usr/local/bin/packer fix -validate=false /home/vsts/work/1/s/ComboBoxes.pkr.hcl
Error parsing template: invalid character '#' looking for beginning of value
##[error]Packer fix command failed with error : ''. This could happen if task does not support packer version.
The # is the first character in the .pkr.hcl file. And changing the beginning of the file will change what character shows up as invalid.
Why is it trying to run "packer fix" instead of "packer build"?
So it turns out that the Packer task in Azure Pipelines doesn't work with current versions of Packer.
Run Packer as part of a script task instead.
- task: PowerShell#2
displayName: 'Packer build'
inputs:
targetType: 'inline'
script: 'packer build $(build.artifactstagingdirectory)/ComboBoxes.pkr.hcl'

Can not deploy Go in Oracle Cloud Function using Cloud Shell

I tried to Creating and Deploying Oracle Cloud Functions by following the official documentation instructions. I can create and deploy using java runtime but when I deploy go runtime always return error.
I tried to init Go function using this command in Oracle Cloud Shell:
fn init --runtime go hello-go
then I tried to deploy it
fn -v deploy --app test
but it returned error like below:
Deploying hello-go to app: test
Bumped to version 0.0.7
Building image bom.ocir.io/bmptwl2psusa/repo/hello-go:0.0.7
FN_REGISTRY: bom.ocir.io/bmptwl2psusa/repo
Current Context: ap-mumbai-1
Sending build context to Docker daemon 5.632kB
Step 1/10 : FROM fnproject/go:dev as build-stage
---> 96c8fb94a8e1
Step 2/10 : WORKDIR /function
---> Using cache
---> 8961dd299ec1
Step 3/10 : WORKDIR /go/src/func/
---> Using cache
---> 5a4c2c6e13f1
Step 4/10 : ENV GO111MODULE=on
---> Using cache
---> 22022ff2fcf8
Step 5/10 : COPY . .
---> 714622a6ff03
Step 6/10 : RUN cd /go/src/func/ && go build -o func
---> Running in 39fedbc476f4
build func: cannot find module for path github.com/fnproject/fdk-go
The command '/bin/sh -c cd /go/src/func/ && go build -o func' returned a non-zero code: 1
Fn: error running docker build: exit status 1
When I'm using java runtime with fn init --runtime java hello-java command, it's successfully deployed, Why always fail when using go?
I tried to run go build -o func in hello-go directory but it's returned:
go: finding module for package github.com/fnproject/fdk-go
go: writing stat cache: mkdir /usr/share/gocode/pkg: permission denied
go: downloading github.com/fnproject/fdk-go v0.0.3
func.go:10:2: mkdir /usr/share/gocode/pkg: permission denied
I know it happened because /usr/share/gocode/ directory is under root user, but I dont know how to change the permission on that folder because Oracle Cloud Shell can not use root user or sudo. (based on this answer)
Maybe I can do it if I use real VM shell or local shell/terminal, but I want to use Oracle Cloud Shell because I just followed official instructions that suggested me using Oracle Cloud Shell, so how to deploy Oracle Cloud Functions with Go runtime using Oracle Cloud Shell?
Mostly the official documentations only give the examples using Java runtime, that make me paranoid when using go.
This is a bug in cloudshell that we are figuring out the best way to solve.
As a short-term workaround you can do this once:
mkdir ${HOME}/gopath
Then set this in your terminal:
export GOPATH=${HOME}/gopath
You should probably edit your ~/.bashrc to set the GOPATH variable automatically so you don't forget

How to debug the cartridge scripts in Openshift?

I want to develop a new cartridge for my own use. I use OpenShift Cartridge Development Kit to start my work. My building script is written in .openshift/action_hooks/build and it can be successfully executed.
But when I tried to use the command displayed on the homepage of the CDK project - "rhc create-app mynewcart http://##YOUR-DOMAIN##/manifest/##YOUR-COMMIT-ID##" - to create an app, I got the following error: "Unable to complete the requested operation due to: An invalid exit code (1) was returned from the server ex-std-node161.prod.rhcloud.com. This indicates an unexpected problem during the
execution of your request."
How can I trace the progress of deploying and find out where is the code that caused the problem? Is there any log file available for me to analyse?
Use the --debug option when running the command and you'll get much more detailed output:
rhc create-app mynewcart http://##YOUR-DOMAIN##/manifest/##YOUR-COMMIT-ID## --debug