Skip to content

Commit

Permalink
Merge pull request #1 from isd-sgcu/feature/ci-workflow
Browse files Browse the repository at this point in the history
[Feature] CI Workflow
  • Loading branch information
Nitiwat-owen authored Dec 23, 2023
2 parents af7a559 + afa13e4 commit 093f8dd
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 5 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: "Build and Deploy"

on:
push:
branches:
- main
- beta
- dev

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21
check-latest: true
cache: true

- name: Download dependencies
run: go mod download

- name: Vet
run: |
go vet ./...
- name: Test
run: |
go test -v -coverpkg ./src/internal/... -coverprofile coverage.out -covermode count ./src/internal/...
go tool cover -func="./coverage.out"
build:
runs-on: ubuntu-latest
needs:
- test

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build Docker image
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: test
33 changes: 33 additions & 0 deletions .github/workflows/run-unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Pull request: Run unit test"

on:
pull_request:
branches:
- main
- beta
- dev

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21
check-latest: true
cache: true

- name: Download dependencies
run: go mod download

- name: Vet
run: |
go vet ./...
- name: Test
run: |
go test -v -coverpkg ./src/internal/... -coverprofile coverage.out -covermode count ./src/internal/...
go tool cover -func="./coverage.out"
28 changes: 28 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Pull request: Build test"

on:
pull_request:
branches:
- main
- beta
- dev

jobs:
docker-build:
name: "Docker build and create an image"
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build Docker image
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: test
49 changes: 49 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Base Image
FROM golang:1.21.4-alpine3.18 as base

# Working directory
WORKDIR /app

# Copy go.mod and go.sum files
COPY go.mod go.sum ./

# Download dependencies
RUN go mod download

# Copy the source code
COPY ./src ./src

# Build the application
RUN go build -o server ./src/.

# Copy config files
COPY ./config ./config

# Adding the grpc_health_probe
RUN GRPC_HEALTH_PROBE_VERSION=v0.3.1 && \
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe

# Create master image
FROM alpine AS master

# Working directory
WORKDIR /app

# Copy grpc_heath_prob
COPY --from=base /bin/grpc_health_probe ./

# Copy execute file
COPY --from=base /app/server ./

# Copy config files
COPY --from=base /app/config ./config

# Set ENV to production
ENV GO_ENV production

# Expose port 3002
EXPOSE 3002

# Run the application
CMD ["./server"]
6 changes: 3 additions & 3 deletions src/internal/service/jwt/jwt.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package jwt
import (
_jwt "github.com/golang-jwt/jwt/v4"
"github.com/isd-sgcu/johnjud-auth/src/config"
"github.com/isd-sgcu/johnjud-auth/src/internal/strategy"
"github.com/isd-sgcu/johnjud-auth/src/pkg/strategy"
)

type serviceImpl struct {
config config.Jwt
strategy strategy.JwtStrategy
}

func NewService(confif config.Jwt, strategy strategy.JwtStrategy) *serviceImpl {
return &serviceImpl{config: confif, strategy: strategy}
func NewService(config config.Jwt, strategy strategy.JwtStrategy) *serviceImpl {
return &serviceImpl{config: config, strategy: strategy}
}

func (s *serviceImpl) SignAuth(userId string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/service/jwt/jwt.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package jwt

import (
"github.com/isd-sgcu/johnjud-auth/src/config"
"github.com/isd-sgcu/johnjud-auth/src/internal/strategy"
"github.com/isd-sgcu/johnjud-auth/src/pkg/strategy"
"github.com/stretchr/testify/suite"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/service/jwt/jwt.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
_jwt "github.com/golang-jwt/jwt/v4"
"github.com/isd-sgcu/johnjud-auth/src/config"
"github.com/isd-sgcu/johnjud-auth/src/internal/service/jwt"
"github.com/isd-sgcu/johnjud-auth/src/internal/strategy"
"github.com/isd-sgcu/johnjud-auth/src/pkg/strategy"
)

type Service interface {
Expand Down

0 comments on commit 093f8dd

Please sign in to comment.