Trying to get the Amplify CI/CD release process to deploy to a separate AWS account - aws-amplify

I'm trying to get the CI/CD release process working so that when I commit to the release branch, it runs the amplify push process.
I AM able to amplify push locally without any issues (after switching branches and checking out the correct amplify environment).
This application has two environments: 'staging' and 'live'. I have two separate AWS accounts for these environments. I created and tested the project initially in staging. When testing was done, I created a new AWS account, created a new Amplify project, and connected it to the 'live' branch in my repo.
When I push commits to the 'live' branch, it starts a build, and gets through provisioning and the pre-build stages. Then I get this:
# Starting phase: build
2022-04-06T17:57:48.997Z [INFO]: Amplify AppID found: xxxxxxxxxxxx. Amplify App name is: Project Production
2022-04-06T17:57:49.080Z [INFO]: Backend environment live found in Amplify Console app: Project Production
2022-04-06T17:57:56.229Z [WARNING]: - Fetching updates to backend environment: live from the cloud.
2022-04-06T17:58:02.363Z [WARNING]: - Building resource api/myapi
2022-04-06T17:58:13.032Z [INFO]: GraphQL schema compiled successfully.
Edit your schema at /codebuild/output/src656745275/src/project-name/amplify/backend/api/myapi/schema.graphql or place .graphql files in a directory at /codebuild/output/src656745275/src/project-name/amplify/backend/api/myapi/schema
2022-04-06T17:58:13.033Z [WARNING]: - Building resource api/restapi
2022-04-06T17:58:17.485Z [WARNING]: - Building resource custom/MagicLinkEmailTemplate
2022-04-06T17:58:17.486Z [WARNING]: - Building custom resources
2022-04-06T17:58:32.284Z [WARNING]: - Building resource custom/MyCustomResource
- Building custom resources
2022-04-06T17:58:48.882Z [WARNING]: - Building resource custom/MyStateMachine
2022-04-06T17:58:48.883Z [WARNING]: - Building custom resources
2022-04-06T17:59:04.647Z [WARNING]: - Building resource custom/HostedZone
- Building custom resources
2022-04-06T17:59:23.823Z [WARNING]: ✔ Successfully pulled backend environment live from the cloud.
2022-04-06T17:59:23.934Z [INFO]:
2022-04-06T17:59:25.368Z [INFO]: Note: It is recommended to run this command from the root of your app directory
2022-04-06T17:59:27.068Z [WARNING]: - Initializing your environment: live
2022-04-06T17:59:33.150Z [WARNING]: - Building resource api/myapi
2022-04-06T17:59:39.389Z [INFO]: GraphQL schema compiled successfully.
Edit your schema at /codebuild/output/src656745275/src/project-name/amplify/backend/api/myapi/schema.graphql or place .graphql files in a directory at /codebuild/output/src656745275/src/project-name/amplify/backend/api/myapi/schema
2022-04-06T17:59:39.390Z [WARNING]: - Building resource api/restapi
2022-04-06T17:59:43.825Z [WARNING]: - Building resource custom/MagicLinkEmailTemplate
2022-04-06T17:59:43.828Z [WARNING]: - Building custom resources
2022-04-06T17:59:50.278Z [WARNING]: - Building resource custom/MyCustomResource
- Building custom resources
2022-04-06T17:59:58.898Z [WARNING]: - Building resource custom/MyStateMachine
- Building custom resources
2022-04-06T18:00:06.435Z [WARNING]: - Building resource custom/HostedZone
- Building custom resources
2022-04-06T18:00:16.067Z [WARNING]: ✔ Initialized provider successfully.
2022-04-06T18:00:17.268Z [INFO]:
2022-04-06T18:00:17.274Z [INFO]: Suggested configuration for new layer versions:
2022-04-06T18:00:17.282Z [INFO]: myappLayerGraphQL
- Access permissions: Maintain existing permissions
- Description: Updated layer version 2022-04-06T18:00:17.273Z
myappLayerAxios
- Access permissions: Maintain existing permissions
- Description: Updated layer version 2022-04-06T18:00:17.273Z
myappLayerLodash
- Access permissions: Maintain existing permissions
- Description: Updated layer version 2022-04-06T18:00:17.273Z
myappLayerStripe
- Access permissions: Maintain existing permissions
- Description: Updated layer version 2022-04-06T18:00:17.273Z
2022-04-06T18:00:17.282Z [INFO]:
2022-04-06T18:00:31.140Z [WARNING]: ✖ An error occurred when pushing the resources to the cloud
2022-04-06T18:00:31.162Z [WARNING]: ✖ There was an error initializing your environment.
2022-04-06T18:00:31.170Z [INFO]: Error: Packaging lambda function failed with the error
Command failed with exit code 1: npm install --production
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion#1, but package-lock.json was generated for lockfileVersion#2. I'll try to do my best with it!
npm WARN tar ENOENT: no such file or directory, open '/codebuild/output/src656745275/src/project-name/amplify/backend/function/myappLayerGraphQL/lib/nodejs/node_modules/.staging/graphql-03f7efb5/language/directiveLocation.mjs'
npm WARN tar ENOENT: no such file or directory, open '/codebuild/output/src656745275/src/project-name/amplify/backend/function/myappLayerGraphQL/lib/nodejs/node_modules/.staging/graphql-03f7efb5/type/directives.mjs'
npm WARN tar ENOENT: no such file or directory, open '/codebuild/output/src656745275/src/project-name/amplify/backend/function/myappLayerGraphQL/lib/nodejs/node_modules/.staging/graphql-03f7efb5/execution/execute.mjs'
......
Those errors go on for about 400 more lines...
I don't know what that .staging directory is or where it came from -- it's not in my actual layer, I don't see references to 'staging' in any files in that entire layer directory.
Any help, please?!

Something changed in Amplify and I started getting a different error message which led me to the solution.
It turns out that I hadn't properly authorized the build process to install the private NPM package I had up on GitHub Package Manager. I dropped the .npmrc file that I had in my local user directory into the directory that contained the package.json for the function that was failing and it started working.
Simple solution made more difficult by bad error logging...

Related

Command "npm run build" exited with 1 in Versel

I am developing a next.js app using MapBox and firebase.
Works fine on localHost but its not getting deployed.
Building
46s
Cloning github.com/Aindrail/CAB_APP (Branch: main, Commit: 34cf9dc)
Cloning completed: 246.128ms
Installing build runtime...
Build runtime installed: 2.486s
No Build Cache available
Installing dependencies...
Detected package-lock.json generated by npm 7...
added 425 packages in 13s
78 packages are looking for funding
run npm fund for details
Detected Next.js version: 12.1.0
Detected package-lock.json generated by npm 7...
Running "npm run build"
cab_app#0.1.0 build
next build
Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry
info - Checking validity of types...
./pages/index.js
33:3 Warning: React Hook useEffect has a missing dependency: 'router'. Either include it or remove the dependency array. react-hooks/exhaustive-deps
54:16 Warning: passHref is missing. See: https://nextjs.org/docs/messages/link-passhref #next/next/link-passhref
./pages/login.js
27:8 Warning: React Hook useEffect has a missing dependency: 'router'. Either include it or remove the dependency array. react-hooks/exhaustive-deps
info - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
info - Creating an optimized production build...
info - Compiled successfully
info - Collecting page data...
Build optimization failed: found page without a React Component as default export in
pages/data/carList
See https://nextjs.org/docs/messages/page-without-valid-component for more info.
Error: Command "npm run build" exited with 1
First of all, you should run npm run build locally before deploying. And properly check your error log, that's already mentioned found page without a React Component as default export in pages/data/carList
You used a component without default export. Check cartList properply. Hopefully, it will be fixed.

Cannot find file './aws-exports' in './src'

I'm on the third module of this AWS tutorial to build a React app with AWS, Amplify and GraphQL but the build keeps breaking. When I ran amplify push --y the CLI generated ./src/aws-exports.js and added the same file to the .gitignore. So I'm not surprised the build is failing, since that file isn't included when I push my changes.
So I'm not sure what to do here. Considering it's automatically added to the .gitignore I'm hesitant to remove it.
Any suggestions?
I'm assuming you are trying to build your app in a CI/CD environment?
If that's the case then you need to build the backend part of your amplify app before you can build the frontend component.
For example, my app is building from the AWS amplify console and in my build settings I have
version: 0.1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- yarn install --frozen-lockfile
build:
commands:
- yarn build
artifacts:
baseDirectory: build
files:
- "**/*"
cache:
paths:
- node_modules/**/*
Note that the backend is building first with the amplifyPush --simple command. This is what generates the aws-exports.js file.
The 'aws-exports.js' file gets created automatically when AWS Amplify runs the CI/CD deployment build process and gets configured with the appropriate settings for the environment you are deploying to.
And for this reason it is included in the .gitignore. You don't want your local test configuration to be used in your production deployment for example.
As per Matthe's answer above the should be generated when the build script runs the 'amplifyPush' command. For some reason this is not working for me at the moment though!
AWS added support to automatically generate the aws-exports.js at build time to avoid getting the error: https://docs.aws.amazon.com/amplify/latest/userguide/amplify-config-autogeneration.html

Automating deployments to Artifactory Distribution Repo

I'm wondering how to deploy artifacts to Artifactory's Distribution repo .
Pushing directly to the distribution repo from gradle (using the gradle-maven plugin) results in the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':artifactoryDeploy'.
> java.io.IOException: Failed to deploy file. Status code: 404 Response message: Artifactory returned the following errors:
Could not find a local repository named my-distribution-repo to deploy to. Status code: 404
Seems I can't push to a repo that's not a local repo. Any ideas?
You can push to a local repository and then distribute the build to a distribution repository.
For example, with the JFrog CLI you can distribute in 3-4 steps:
Building a Gradle project.
Publishing the build information.
Promoting the build (Optional).
Distributing the build.

Blogdown: Deploy with Netlify fails with standard theme

I just installed a new RStudio project with blogdown + standard theme from scratch and deployed it via GitHub to Netlify. A process which worked all the time with older versions of hugo-lithium-theme. But now it does not deploy. I changed nothing at all: just installed and pushed it via my GitHub-repo to Netlify
The last few lines with error message were:
10:03:08 PM: Build complete: exit code: 0
10:03:08 PM: Cleaning up docker container
10:03:08 PM: Starting to deploy site from 'publish'
10:03:08 PM: Deploying to CDN 10:03:09 PM: Failed to deploy publish to CDN
10:03:09 PM: stat /mnt/build-work/buildbot-796257821/repo/publish: no such file or directory
10:03:09 PM: Finished processing build request in 16.651393261s
I was using HUGO_VERSION 0.27
[Update] I just noticed this line in the error log:
10:03:08 PM: Starting to deploy site from 'publish'
You probably specified a wrong folder name for the publish directory. The default for Hugo is public instead of publish. See Section 3.1 of the blogdown book for some sample settings.
Occasionally Netlify fails to build a site (for reasons that I don't understand), and you can try to click the "Trigger deploy" button in the "Deploys" tab on https://app.netlify.com if you want to redeploy the master branch of your repo:
Or click the specific failed deploy then click the "Retry deploy" button:

Plugin to create project tar file and publish it to Nexus in sbt?

Is there some kind of sbt plugin that enables publishing result to repository (i.e nexus).
I heard about sbt-native-packager but I need to create tarball (*.tar) and publish it to repository. I prepeare my own task that depends on dist and it repackages result from zip to tar. Next I just try to modify it with description available here: https://groups.google.com/forum/#!topic/play-framework/Td389FbdgCY. Unfortunately I get:
[error] java.lang.AssertionError: assertion failed: Internal task engine error: nothing running. This usually indicates a cycle in tasks.
[error] Calling tasks (internal task engine state):
[error] Task((taskDefinitionKey: ScopedKey(Scope(Select(ProjectRef(file:/C:/src/cms/,cms)),Global,Global,Global),projectDependencyArtifacts))) -> Calling
What is more additionaly to publishing package in repository I need to automatically create create tag for release in mercurial.

Resources