Giter Site home page Giter Site logo

devenes / containerization-dummy-go Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 6.07 MB

Simple Go server containerization using GitHub Actions, Jenkins and AWS CodeBuild.

License: MIT License

Go 83.09% Dockerfile 16.91%
go golang docker dockerfile jenkins buildspec codecommit codebuild codebuild-deploy developer-tools

containerization-dummy-go's Introduction

CI/CD with Golang

Go Docker Build And Push

Part 1

  • Since we want to trigger the CI/CD process with the push we will perform within the GitHub ecosystem, we have pushed the source code to our own repo.

  • We used GitHub Actions, the Pipeline as Code tool offered by GitHub, to trigger the process with the push commit.

  • A script was written to perform the Docker build process with the trigger and to give the version number.

FROM golang:1.16-alpine

WORKDIR /app

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY *.go .

RUN go build -o /dummy-app
EXPOSE 8080

CMD ["/dummy-app"]
  • The username and password of the Docker Hub Registry, which is the environment we will push our Docker images to after we build, are defined as secrets in GitHub Repo Settings and used as environment variables in the GitHub Actions pipeline.

  • To trigger our Jenkins pipeline, we add the curl command to the end of our GitHub Actions pipeline and our token that we defined in Jenkins to send a request to the webhook link of the server.

    • Note: Token is defined as environment variable in secrets from GitHub repo settings.

In our Jenkins pipeline, we first stop and delete the running container and clean up the old images. Then we download the Image that we have determined with the current tag number and run it as a container.

We give 80 as the port number in the docker run command so that our Jenkins running on 8080 and our Go application do not conflict with each other.

The output of our operations looks like this:

Our image that we pushed to Docker Hub after we got the Build:

Part 2

Before starting to operate on CodeBuild, we give some permissions to reach the ECR and to examine the post-process logs in detail:

We selected our repo by logging into CodeBuild with GitHub. Then we edit the build spec file with the links we got from the ECR settings:

version: 0.2

phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...
      - docker build -t mydockerrepo .
      - docker tag mydockerrepo:latest 32976713052.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker image...
      - docker push 32976713052.dkr.ecr.us-east-1.amazonaws.com/mydockerrepo:latest

We see that our action steps have been successfully completed:

image

At the end of our Image Build process, we come to the repo we opened on ECR to see if our push to ECR was successful:

image

containerization-dummy-go's People

Contributors

dependabot[bot] avatar devenes avatar

Watchers

 avatar  avatar

Forkers

kunalbiswal

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.