Jenkins and ECR
JenkinsandECR
Firstofall,createarepositoryintheAmazonECRRepositories
IgetaURLasfollow
703986672610.dkr.ecr.us-west-2.amazonaws.com/netsuite
FindmyAWSsecurityandkey,itseemsIdonothavepermissiontogenerateone.
[AWSManagementConsole]—>[MySecurityCredentials]
IgetmycredentialsfromAWS,inmycasethecontentsareasfollowing
>cat~/.aws/credentials
[default]
aws_access_key_id=AKIAxxxxxxxxxxx
aws_secret_access_key=B9BQoF5mxxxxxxxxxxxxxxxxxxxx
>cat~/.aws/config
[default]
region=us-west-2
HereisthestepsforinstalltheAWS-cliifyoudonothaveoneyet
>sudoaptinstallpython3-pip
>pip3installawscli--upgrade--user
Testmypermissions
>awsecrget-login--no-include-email
ItwillgeneratealogincommandandIjustcopyandrunthat
ThenIcanlistalltherepoIhave
>awsecrdescribe-repositories
OnmyEC2machine,Isetthe.awsthenIcanlisttherepositoriesaswell.
TrytobuildthelocalJenkinsDockerbuildENVfortesting
>dockerbuild-fdeployment/jenkins/Dockerfile.build-tjenkins-test:1.0.
RunthebuildingENV
>dockerrun-ti--namejenkins-testjenkins-test:1.0/bin/bash
Removetheapplicationifneeded
>dockerrmjenkins-test
SomeimportantconfigurationchangetomakeitworkingonJenkinsPipeline
IntheDockerfile.buildwhichpreparethebuildENVDockerImage,IaddthetoolAWScommandline
RUNapt-getinstall-ypython3-pip
RUNpip3installawscli--upgrade--user
RUNln-s/root/.local/bin/aws/usr/local/bin/aws
Iconfigurethe.awscredentialsinformationontheJenkinsmachine.IwillmappingthattotheDockeraswellinthepipelineconfiguration
dockerfile{
filename'deployment/jenkins/Dockerfile.build'
args'-uroot:root-v/home/ubuntu/.aws:/root/.aws-v$HOME/.m2:/root/.m2-v/var/run/docker.sock:/var/run/docker.sock'
}
IamusingDockertostartjenkins,sotheuserisubuntuonMaster,jenkinswasstartingwithrootinDocker,thenthebuildENVisusingrootasuseraswell.Sothereissomepermissionandusersconflicts.Iwillfixthatlater.
HereistheBuildProcessfortheDocker
stage('BuildDockerImage'){
steps{
sh'''
dockerbuild-fdeployment/docker/Dockerfile-txxxxxxx.dkr.ecr.us-west-2.amazonaws.com/netsuite:1.5.
rm-frtarget
'''
}
}
HereisthestepstosendtoECR
stage('ReleasetoECR'){
steps{
sh'''
$(awsecrget-login--no-include-email)
dockerpushxxxxxxxxx.dkr.ecr.us-west-2.amazonaws.com/netsuite:1.5
'''
}
}
References:
https://docs.aws.amazon.com/AmazonECR/latest/userguide/ECR_AWSCLI.html#AWSCLI_push_image
https://medium.com/@bhadrajatin/ecr-login-from-jenkins-using-pipeline-and-docker-222b696694e0
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html