Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
44 changes: 44 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Git files
.git
.gitignore
.github

# Documentation
*.md
!README.md
docs/

# Docker files (dev/prod configs not needed in image)
docker/dev/
docker/prod/

# Environment files
.env
.env.*

# Build artifacts
bin/
*.bin

# IDE and editor files
.vscode/
.idea/
*.swp
*.swo
*~

# OS files
.DS_Store
Thumbs.db

# Test files
*_test.go
test/

# Logs
*.log
logs/

# Temporary files
tmp/
temp/
164 changes: 164 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
name: CI/CD Pipeline

on:
push:
branches: [master, dev, staging]
pull_request:
branches: [master]

env:
DOCKER_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/gochat
GO_VERSION: '1.23'

jobs:
unit-test:
name: Unit Tests
runs-on: ubuntu-latest

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

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Install dependencies
run: go mod download

- name: Check code formatting
run: |
if [ -n "$(go fmt ./...)" ]; then
echo "Code is not formatted. Run 'make fmt' to fix."
exit 1
fi

- name: Run go vet
run: go vet ./...

- name: Run unit tests
run: go test -v -short -race -coverprofile=coverage.out ./...

- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.out
retention-days: 7

integration-test:
name: Integration Tests
runs-on: ubuntu-latest
needs: unit-test

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

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Install dependencies
run: go mod download

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Start services for integration tests
run: |
docker compose -f docker-compose.yml -f deployments/docker-compose.test.yml up -d --build
echo "Waiting for services to be healthy..."
sleep 30

- name: Run integration tests
run: go test -v ./...

- name: Stop services
if: always()
run: docker compose -f docker-compose.yml -f deployments/docker-compose.test.yml down

build:
name: Build Docker Image
runs-on: ubuntu-latest
needs: [unit-test, integration-test]

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

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract metadata
id: meta
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
push: false
tags: |
gochat:latest
gochat:${{ steps.meta.outputs.sha_short }}
gochat:${{ steps.meta.outputs.branch }}
cache-from: type=gha
cache-to: type=gha,mode=max
load: true

- name: Save Docker image
run: docker save gochat:latest | gzip > gochat-image.tar.gz

- name: Upload Docker image artifact
uses: actions/upload-artifact@v4
with:
name: docker-image
path: gochat-image.tar.gz
retention-days: 1

push:
name: Push to Docker Hub
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'

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

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract metadata
id: meta
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
push: true
tags: |
${{ env.DOCKER_IMAGE }}:latest
${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.sha_short }}
${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.branch }}
cache-from: type=gha
cache-to: type=gha,mode=max

17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

96 changes: 96 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# GoChat Multi-Container Deployment - Change Log

## 2025-12-30

### Session 3: Added CI/CD Pipeline

**Makefile**
- Added `test` - Run all tests with race detector
- Added `test-coverage` - Generate HTML coverage report
- Added `test-unit` - Run unit tests only
- Added `test-integration` - Run integration tests with Docker
- Added `fmt` - Format code with go fmt
- Added `fmt-check` - Check if code is properly formatted
- Added `vet` - Run go vet static analysis
- Added `lint` - Run golangci-lint
- Added `build-binary` - Build gochat binary
- Added `build-image` - Build Docker image

**.github/workflows/ci-cd.yml**
- Created GitHub Actions CI/CD workflow
- Test job: go fmt, go vet, tests with Redis service container
- Build job: Docker image with caching
- Push job: Push to Docker Hub with multiple tags (latest, branch, git-sha)
- Deploy jobs: Optional deployment to dev/staging/prod (commented out, requires server setup)

**docker-compose.test.yml**
- Created test environment with Redis and etcd service containers
- Test runner service for integration tests

**docker/Dockerfile.test**
- Created test Dockerfile for running tests in Docker

**scripts/deploy.sh**
- Created deployment script for manual deployments
- Supports dev, staging, prod environments
- Pulls image, stops old services, starts new services

**config/staging/**
- Created staging configuration (copied from dev)

**docker-compose.staging.yml**
- Created staging environment override
- Uses staging config with info log level

**README.md**
- Added CI/CD Pipeline section with workflow description
- Added GitHub Secrets setup instructions
- Added branch strategy documentation
- Added manual deployment commands
- Added testing and building commands to Commands section

---

### Session 2: Removed entrypoint.sh

**tools/network.go**
- Added `GetContainerIP()` - Returns container's actual IPv4 address
- Added `GetServiceAddress()` - Replaces 0.0.0.0 with container IP for etcd registration

**logic/publish.go**
- Changed `addRegistryPlugin()` - ServiceAddress now uses `tools.GetServiceAddress(network, addr)`

**connect/rpc.go**
- Changed `addRegistryPlugin()` - ServiceAddress now uses `tools.GetServiceAddress(network, addr)`

**docker/Dockerfile**
- Removed entrypoint.sh copy and chmod commands
- Changed from `ENTRYPOINT ["/app/entrypoint.sh"]` to `CMD ["/app/gochat", "-module", "api"]`

**docker-compose.yml**
- All services: Removed `ETCD_HOST` and `REDIS_HOST` environment variables
- All services: Changed command from `["-module", "xxx"]` to `["/app/gochat", "-module", "xxx"]`

**docker/entrypoint.sh**
- Deleted (no longer needed)

---

### Session 1: Cleaned Up Legacy Files

**Removed directories:**
- `docker/dev/` - Supervisord configs for development (10 files)
- `docker/prod/` - Supervisord configs for production (10 files)

**Removed files:**
- `run.sh` - Legacy single-container deployment script
- `reload.sh` - Legacy reload script

**README.md**
- Removed "Legacy Deployment" section mentioning `run.sh`

---

## Future Updates

Add entries above in reverse chronological order (newest first).
Loading