https://github.com/devenes/containerization-dummy-go
Simple Go server containerization using GitHub Actions, Jenkins and AWS CodeBuild.
https://github.com/devenes/containerization-dummy-go
aws buildspec code-deploy codebuild codebuild-deploy codecommit developer-tools docker dockerfile github-actions go golang jenkins jenkins-pipeline jenkinsfile
Last synced: 4 months ago
JSON representation
Simple Go server containerization using GitHub Actions, Jenkins and AWS CodeBuild.
- Host: GitHub
- URL: https://github.com/devenes/containerization-dummy-go
- Owner: devenes
- License: mit
- Created: 2022-03-14T22:17:27.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-03T01:08:55.000Z (about 2 years ago)
- Last Synced: 2025-01-03T15:44:23.616Z (5 months ago)
- Topics: aws, buildspec, code-deploy, codebuild, codebuild-deploy, codecommit, developer-tools, docker, dockerfile, github-actions, go, golang, jenkins, jenkins-pipeline, jenkinsfile
- Language: Go
- Homepage:
- Size: 5.93 MB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CI/CD with Golang
[](https://github.com/devenes/containerization-dummy-go/actions/workflows/go.yml) [](https://github.com/devenes/containerization-dummy-go/actions/workflows/dockerx.yml)
## 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-alpineWORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod downloadCOPY *.go .
RUN go build -o /dummy-app
EXPOSE 8080CMD ["/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.2phases:
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]()