Tech is an hell ocean, I know nothing but drowning,...being a mermaid is kinda my style.

hehe... tottaly screwed that line. The point was, there will be always so much to learn because everything is evolving consistently we cant be experts in all but atleast try to adapt along with the changes to our benefits. :)

This post is very brief just to get idea and then start Questioning -> exploring -> implementing -> Notes and thoughts -> Optimizing -> Implementing -> Sharing

using codebuild building an artifact and docker image of my java application and pushing it into s3 and ecr respectively.
to understand the gist

  1. S3 Input bucket has source application code zipped
  2. S3 Output bucket will have the artifact
  3. ECR: will have the docker image
  4. Codebuild: taking my java application, producing artifact and docker image, pushing it into ECR and S3
  5. IAM role and Policy: for codebuild to access S3 and ECR.

Using terraform to execute the workflow

  1. Creat two buckets - Input and Output.
  2. ECR Repo to store the docker image.
  1. Create a codebuild project..desribe the workflow.
  1. Inorder to codebuild to execute it needs permission to read and write access to respective S3 buckets and write access to ECR.
  1. Want to run build image in Private network so create VPC, and run docker images using farget.
  1. ECS Fargate
    once the codebuild is executed our docker image is ECR repo. To run this executable image using fargate, Fargate needs access permission to ECr repo. hence create role and attach policy to it.
  1. Write your .yml file or could use this as reference
    This .yml file codebuild will read define actions what codebuild must do in this file.
  1. Dockerfile to build an image.
  1. shellscript
    I am running shell script inside codebuild and command is defined in my.yml file. This will take care of -
    a. builds my java application,
    b. reads and run Dockerfile to build docker image,
    c. do the dynamic porting and run the docker image
    d. does the health check..i.e. if my container is running if not displays the log.
    Not mandatory though..its for to check the build is happenig correctly and eye candy for beginners. One chan just mention build comands and Dockerfile command seperately instead of sheelscript.

declare -r app_host_port=${2:?"$(echo "host port for accessing the container")"}
declare -r app_container_port=${2:?"$(echo " port that the application will start on inside the container")"}
declare -r docker_container_name="give_name"
declare -r docker_image_tag="${docker_container_name}_${env}"
declare -r app_healthcheck_url="http://localhost:$app_host_port"

# Build Source!
./gradlew clean build shadowJar
# Dockerize!
docker build -f ./Dockerfile ./ -t "$docker_image_tag"

echo " Start container named $docker_container_name from the image tagged $docker_image_tag."
docker run --name "$docker_container_name"  -d -i -p $app_host_port:$app_container_port -t $docker_image_tag:latest

echo "Doing health check"
for backoff_sec in 1 2 3 4 5 2 3; do
    sleep $backoff_sec
    if [[ "$(curl -s $app_healthcheck_url)" != "Hello, world!" ]]
    then echo "INFO Waited for ${backoff_sec} sec before running health check."
    else echo "INFO Health check succeeded."

echo "INFO Display $docker_container_name docker container process status."
docker container ps --filter "name=$docker_container_name"

echo "INFO Spit out last few log lines to indicate what's happened."
docker logs "$docker_container_name" | tail

  1. Source code.
    USe your basic hello worl java application or replace it basic python application and do the desired changes.

Note: This workflow tends to list serious of questions, and demands clear understanding of concepts which are way important such as whats gradlew, jar?, docker expose8080, artefact, docker image, Fargate networking, VPC etc...
lets take it slow and build up gradually.