What would be the best practices for setting up CI for an Amplify React Native project?
The practice seems to be for aws-exports.js
to be in .gitignore
. Should it be recreated on the CI?
I assume that the CI should run amplify push --yes
itself prior to building the project, which would regenerate that file, and maybe use its own environment name.
I'd like to use AppCenter to build the binaries, so I'd need to first supply AWS credentials from the CI script so that the amplify push step can work.
I'd assume this would be a common usage scenario but I couldn't find anything while searching, how is everyone else doing it?
I assume that the CI should run amplify push --yes itself prior to building the project, which would regenerate that file, and maybe use its own environment name.
Yes. You should push your backed using our headless scripts.
Amplify Console uses the following script to do the push
https://gist.github.com/swaminator/7408de774e24ecf031d0d9928f1fbae5
I was able to create a pre build script with the following contents:
appcenter-pre-build.sh
#!/usr/bin/env bash
npm install -g @aws-amplify/cli
AWSCONFIG="{\
\"configLevel\":\"general\"\
}"
AMPLIFY="{\
\"envName\":\"${AMPLIFY_ENV}\"\
}"
PROVIDERS="{\
\"awscloudformation\":${AWSCONFIG}\
}"
CODEGEN="{\
\"generateCode\":false,\
\"generateDocs\":false\
}"
amplify init --amplify ${AMPLIFY} --providers ${PROVIDERS} --codegen ${CODEGEN} --yes
amplify push --codegen $CODEGEN --yes
Also needed to set the following ENV variables: AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION
and the custom one AMPLIFY_ENV
(see code above, it's the amplify env name).
Leaving this here in hope that it helps someone. Should be similar for other CI build systems.
Fwiw this appcenter-pre-build.sh
is what worked for me:
#!/usr/bin/env bash
npm install -g @aws-amplify/cli
AWSCONFIG="{\
\"accessKeyId\":\"${AWS_ACCESS_KEY_ID}\",\
\"secretAccessKey\":\"${AWS_SECRET_ACCESS_KEY}\",\
\"region\":\"${AWS_REGION}\"\
}"
AMPLIFY="{\
\"envName\":\"${AMPLIFY_ENV}\"\
}"
PROVIDERS="{\
\"awscloudformation\":${AWSCONFIG}\
}"
CODEGEN="{\
\"generateCode\":false,\
\"generateDocs\":false\
}"
amplify init --amplify ${AMPLIFY} --providers ${PROVIDERS} --codegen ${CODEGEN} --yes
amplify push --codegen $CODEGEN --yes
With the same environment variables as mentioned in @andreialecu's post
Most helpful comment
I was able to create a pre build script with the following contents:
appcenter-pre-build.sh
Also needed to set the following ENV variables:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION
and the custom oneAMPLIFY_ENV
(see code above, it's the amplify env name).Leaving this here in hope that it helps someone. Should be similar for other CI build systems.