Step 1: First of all you have to select aws code build service.
After that click on create build project
After that in source provider select Github and click on connect to github
Then click on switch to editor
COPY
COPY
version: 0.2
#env:
#parameter-store:
# key: "value"
# key: "value"
phases:
install:
#If you use the Ubuntu standard image 2.0 or later, you must specify runtime-versions.
#If you specify runtime-versions and use an image other than Ubuntu standard image 2.0, the build fails.
runtime-versions:
python: 3.11
pre_build:
commands:
- pip install -r day-14/simple-python-app/requirements.txt
# - command
build:
commands:
- cd day-14/simple-python-app
- echo "Building Docker Image"
- docker build -t "<>"
- docker push <>
post_build:
commands:
- echo "Build is successful"
Then click on build project
Step 2 : Then search for systems manager
Then go to the parameter store
Step 3 : Then go to the build space add this code
COPY
COPY
version: 0.2
env:
parameter-store:
DOCKER_REGISTRY_USERNAME: /myapp/docker-credentials/username
DOCKER_REGISTRY_PASSWORD: /myapp/docker-credentials/password
DOCKER_REGISTRY_URL: /myapp/docker-registry/url
phases:
install:
runtime-versions:
python: 3.11
pre_build:
commands:
- echo "Installing dependencies..."
- pip install -r day-14/simple-python-app/requirements.txt
build:
commands:
- echo "Running tests..."
- cd day-14/simple-python-app/
- echo "Building Docker image..."
- echo "$DOCKER_REGISTRY_PASSWORD" | docker login -u "$DOCKER_REGISTRY_USERNAME" --password-stdin "$DOCKER_REGISTRY_URL"
- docker build -t "$DOCKER_REGISTRY_URL/$DOCKER_REGISTRY_USERNAME/simple-python-flask-app:latest" .
- docker push "$DOCKER_REGISTRY_URL/$DOCKER_REGISTRY_USERNAME/simple-python-flask-app:latest"
post_build:
commands:
- echo "Build completed successfully!"
artifacts:
files:
- '**/*'
base-directory: ../simple-python-app
Step 4 : Then click on build code
Step 5: Then go to the code pipeline
Then click on create pipeline
Then click on connect to github
Skip the deploy stage
After that click on create pipeline
Step 6: Then search for aws code deploy service
Then click on code deploy
Then click on create application
Then create aws ec2 instance
Then you need to create tags
Then you need to install code deploy agent on ec2 instance you can refer this link
docs.aws.amazon.com/codedeploy/latest/userg..
Then you need to create IAM Role
And after that you need to grand permission to code deploy
After that assign this role to the ec2 instance
Then go to the code deploy and create deployment group
Then click on create deployment group
Then you need to click on create deployment
Then click on create deployment
Then go to the code pipeline
Then click on edit
Then click on add stage
Then click on add action group