Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI/CD Pipeline

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

# Permissions required to push images to GitHub Container Registry (GHCR)
permissions:
contents: read
packages: write

jobs:
# ==================================================
# Stage 1: Continuous Integration (CI) - Test & Build
# ==================================================
test-and-build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
cache: false

- name: Install Dependencies
run: make deps

- name: Run Tests
run: make test

- name: Build Binary (Verify Compilation)
run: make build

# ==================================================
# Stage 2: Continuous Deployment (CD) - Docker Push
# ==================================================
docker-push:
needs: test-and-build # Only run if tests passed
if: github.event_name == 'push' # Only on push to main (skip on PR)
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest
type=sha,format=short

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
22 changes: 14 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# Makefile for api-gateway-avner

BINARY_NAME=motzklist-api-gateway
BUILD_DIR=./build
SRC_DIR=./

# Default command: runs the server
# Default command: runs the server (using '.' to include all files in package)
.PHONY: run
run:
go run $(SRC_DIR)main.go
go run .

# Builds the binary
# Builds the binary (using '.' to include all files in package)
.PHONY: build
build:
go build -o $(BUILD_DIR)/$(BINARY_NAME) $(SRC_DIR)main.go
go build -o $(BUILD_DIR)/$(BINARY_NAME) .

# Cleans up the build directory
.PHONY: clean
Expand All @@ -22,4 +19,13 @@ clean:
# Installs dependencies
.PHONY: deps
deps:
go mod download
go mod download

# Runs tests
.PHONY: test
test:
@if command -v gotestsum > /dev/null; then \
gotestsum --format testname ./...; \
else \
go test -v ./...; \
fi
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module api-gateway-avner

go 1.25.4
module api-gateway-avner
go 1.25.4
Loading