So for few days now I am trying to perform cicd using bitbucket pipeline.
I have successfully built the docker Image but the process of uploading it to the AWS ec2 instance is being an issue for me
what I want is to pull the image in the aws instance and directly run a docker container and upload it to the container...
I am using ssh key to login in the aws ec2. I would love to know if there is any alternative option like - S3
please help me with this
pipeline:
image: atlassian/default-image:3 # Base Docker image to run the pipeline
pipelines:
branches:
dev-cicd:
- step:
name: Build Docker image
script:
- echo "Building Docker image..."
- docker build -t xyzzy .
- docker tag xyz:latest xyz/xyz:latest
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker push xyz/xyz:latest
- step:
name: Deploy to EC2
script:
- >
ssh ec2-user@xyzIP << 'EOF'
set -e # Fail on first error
docker pull xyz/xyz:latest || { echo "Docker pull failed"; exit 1; }
if docker ps -q -f name=my-running-container; then
docker stop my-running-container
docker rm my-running-container
fi
docker run -d --name my-running-container xyz/xyz:latest || { echo "Docker run failed"; exit 1; }
EOF
This I the pipeline I have tried
Docker image is successful
but ec2 Login is being a problem