Skip to content

Justin-Sniesak/go-docker-githubactions-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔄 Go + Docker + GitHub Actions CI/CD Pipeline

End-to-end CI/CD lab automating Go application builds through Docker and GitHub Actions, integrated with GCP Artifact Registry.

Built reproducible, production-style pipelines — from local build → tag → push → deploy — and fully documented four real debugging cycles (auth, build, tag, and workflow errors).

📦 100% reproducible builds · 🔁 Automated deploys via GitHub Actions · 🧩 Validated artifact storage in GCP

All commands should be run using bash.


🚀 Project Overview

This project demonstrates a complete CI/CD workflow:

  1. Go app — simple program that outputs your name, date, and time.
  2. Dockerized container — validated locally with docker ps -a.
  3. Artifact Registry integration — authenticated and pushed via gcloud.

🕒 Note on Timezone

Please note, time returned is in UTC. If running locally, will default to PDT, this can easily be changed to the timezone of your choice if desired in the code.


Repository Structure

├── .github/
    └── workflows/
        ├── README.md
        └── go-dockerimage-pipeline.yaml
├── Deployment
├── Docs
    └── OPERATIONS_LOG.md
├── Dockerfile
├── README.md
└── utc-time-date.go


🧠 What This Shows

  • Real-world CI/CD pipeline for a containerized Go app.
  • Hands-on use of GitHub Actions, Docker, and Google Cloud.
  • Clean, reproducible workflow anyone can perform.

🧩 Stack

Layer Tool
Language Go
Containerization Docker
CI/CD GitHub Actions
Cloud Google Cloud Platform (Artifact Registry)

🧰 Prerequisites


⚙️ Reproduction Steps

1️⃣ Clone the repo

git clone https://github.com/justin-sniesak/go-docker-githubactions-pipeline.git

2️⃣ Build and run locally

docker build -t utcTimeDate:latest .

docker run utcTimeDate

Verify output:

Hello, the date is 10/11/2025, and the time is 07:45 PM.

3️⃣ Authenticate with Google Cloud, create the artifact repo serviceaccount, attach the artifact registry IAM policy binding to the service account, create the API key, then connect your GitHub repo to your GCP project

gcloud auth configure-docker

gcloud iam service-accounts create github-actions-sa \ --display-name="GitHub Actions Service Account"

gcloud projects add-iam-policy-binding <your-project> --member="serviceAccount:github-actions-sa@<your-project>.iam.gserviceaccount.com" --role="roles/artifactregistry.writer"

gcloud iam service-accounts keys create key.json \ --iam-account=github-actions-sa@<your-project>.iam.gserviceaccount.com

cat key.json

GitHub repo -> Settings -> Secrets and Variables -> New repository secret -> paste the ENTIRE JSON key file from the previous step and save

4️⃣ Push image to Artifact Registry

docker tag gotime:latest us-west1-docker.pkg.dev/<your-project>/<repo-name>/utcTimeDate:latest

docker push us-west1-docker.pkg.dev/<your-project>/<repo-name>/utcTimeDate:latest

5️⃣ GitHub Actions CI/CD

Builds Docker image

Outputs current time and date in the pipeline log

🧾 Sample Output (GitHub Actions)

Run docker run --rm utcTimeDate docker run --rm utcTimeDate shell: /usr/bin/bash -e {0} Hello, the date is 10/12/2025, and the time is 06:10 AM.

💡 Lessons Learned

Create, authenticate to and push Docker image to GCP Artifact Registry

CI/CD pipelines don’t have to be complex to be production-grade

Debugging is part of mastery — not failure

🛠️ Troubleshooting

All screenshots included in repo.

Issue 1: GCP Authentication Failure

  • Problem: Incorrect account was set as active, blocking Docker image push to Artifact Registry
  • Solution: Switched to correct active account via gcloud config set account

Issue 2: Docker Build Failure

  • Problem: Dockerfile and Go code were not at root level, causing path errors
  • Solution: Moved both files to root directory to resolve COPY instruction

Issue 3: Pipeline Failure

  • Problem: Renamed code file but didn't update GitHub Actions YAML reference
  • Solution: Updated workflow file to match new filename, build completed successfully (RC0)

Issue 4: Tag and Push to GCP Failure

  • Problem: Build is failing when attempting to tag the built docker image prior to pushing to Artifact Repo in GCP.
  • Solution: Added unit test job, tagged image earlier in build process, broke tag/push job into two different jobs

🏁 Author

Justin Sniesak

Infrastructure Engineer | Cloud | Kubernetes | CI/CD | Go 📍 Seattle, WA

About

Lightweight demo automating Go builds through Docker and GitHub Actions with push-to-deploy via GCP Artifact Registry.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published