-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.github/* | ||
.env* | ||
go.* | ||
*.md | ||
*.pem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Build and Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
tags: | ||
- 'v*' | ||
pull_request: | ||
branches: | ||
- develop | ||
|
||
env: | ||
GCP_PROJECT_ID: nghe-nhan-trading | ||
GCP_REGION: asia-southeast1-b | ||
IMAGE: teleport-discord-bot/teleport-discord-bot | ||
K8S_ENVIRONMENT: dev | ||
|
||
jobs: | ||
build-and-test: | ||
name: Build and Test | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.23 | ||
|
||
- name: Run tests | ||
run: | | ||
go test ./... | ||
docker-release: | ||
name: Docker Release | ||
needs: build-and-test | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Authenticate to Google Cloud | ||
uses: google-github-actions/auth@v1 | ||
with: | ||
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }} | ||
|
||
- name: Set up Cloud SDK | ||
uses: google-github-actions/setup-gcloud@v1 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Configure Docker | ||
run: | | ||
gcloud auth configure-docker ${{ env.GCP_REGION }}-docker.pkg.dev | ||
- name: Extract version from tag | ||
id: get_version | ||
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: | | ||
${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.IMAGE }}:latest | ||
${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.IMAGE }}:${{ steps.get_version.outputs.VERSION }} | ||
# - name: Create GitHub Release | ||
# uses: softprops/action-gh-release@v1 | ||
# with: | ||
# generate_release_notes: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
FROM golang:1.23-alpine AS builder | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Install git and ca-certificates | ||
RUN apk add --no-cache git ca-certificates \ | ||
gcc \ | ||
musl-dev | ||
|
||
# Copy go mod and sum files | ||
COPY go.mod go.sum ./ | ||
|
||
# Download dependencies | ||
RUN go mod download | ||
|
||
# Copy the source code | ||
COPY . . | ||
|
||
# Build the application | ||
RUN go install --tags musl ./... | ||
|
||
|
||
# Final stage | ||
FROM alpine:latest | ||
|
||
# Install ca-certificates for HTTPS | ||
RUN apk --no-cache add ca-certificates | ||
|
||
# Create a non-root user | ||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Copy the built binary from builder | ||
COPY --from=builder /go/bin/* /usr/bin/ | ||
COPY auth.pem auth.pem | ||
|
||
# Change to non-root user | ||
USER appuser | ||
|
||
# Command to run the executable | ||
ENTRYPOINT ["teleport-discord-bot"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Makefile for Teleport Discord Bot | ||
|
||
# Go parameters | ||
GOCMD=go | ||
GOBUILD=$(GOCMD) build | ||
GOTEST=$(GOCMD) test | ||
GOMOD=$(GOCMD) mod | ||
BINARY_NAME=teleport-discord-bot | ||
MAIN_PATH=./cmd/teleport-discord-bot | ||
|
||
# Environment | ||
export GO111MODULE=on | ||
|
||
# Default target | ||
.PHONY: all | ||
all: test build | ||
|
||
# Build the application | ||
.PHONY: build | ||
build: | ||
$(GOBUILD) -o $(BINARY_NAME) $(MAIN_PATH) | ||
|
||
# Run tests | ||
.PHONY: test | ||
test: | ||
$(GOTEST) -v ./... | ||
|
||
# Run tests with coverage | ||
.PHONY: test-coverage | ||
test-coverage: | ||
$(GOTEST) -coverprofile=coverage.out ./... | ||
$(GOCMD) tool cover -html=coverage.out | ||
|
||
# Clean up build artifacts | ||
.PHONY: clean | ||
clean: | ||
rm -f $(BINARY_NAME) | ||
rm -f coverage.out | ||
|
||
# Lint the code | ||
.PHONY: lint | ||
lint: | ||
golangci-lint run | ||
|
||
# Install dependencies | ||
.PHONY: deps | ||
deps: | ||
$(GOMOD) download | ||
$(GOMOD) tidy | ||
|
||
# Run the application locally | ||
.PHONY: run | ||
run: | ||
$(GOBUILD) -o $(BINARY_NAME) $(MAIN_PATH) | ||
./$(BINARY_NAME) | ||
|
||
# Development setup | ||
.PHONY: setup | ||
setup: | ||
@echo "Installing development tools..." | ||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | ||
|
||
.PHONY: digest | ||
digest: | ||
npx ai-digest --whitespace-removal | ||
|
||
# Help target | ||
.PHONY: help | ||
help: | ||
@echo "Available targets:" | ||
@echo " all - Run tests and build the application" | ||
@echo " build - Build the application" | ||
@echo " test - Run tests" | ||
@echo " test-coverage - Run tests with coverage report" | ||
@echo " clean - Remove build artifacts" | ||
@echo " lint - Run golangci-lint" | ||
@echo " deps - Download and tidy dependencies" | ||
@echo " run - Build and run the application" | ||
@echo " setup - Install development tools" | ||
@echo " help - Show this help message" |