Skip to content

Commit

Permalink
Merge pull request #2 from just-pthai-it/development
Browse files Browse the repository at this point in the history
refactor project's structure
  • Loading branch information
just-pthai-it authored Oct 10, 2024
2 parents 2b625d1 + 26ecde8 commit a08e8d3
Show file tree
Hide file tree
Showing 65 changed files with 634 additions and 307 deletions.
12 changes: 6 additions & 6 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
root = "."
tmp_dir = "build"
tmp_dir = "bin"

[build]
args_bin = []
bin = "./build/main"
cmd = "go build -o ./build/main ./app/."
bin = "./bin/${SERVICE_NAME}"
cmd = "go build -o ./bin/${SERVICE_NAME} ./services/${SERVICE_NAME}/app/."
# cmd = "go run ./app/."
# cmd = "go build -o ./build/main ./app/. && dlv exec ./build/main --headless --continue --listen=:40000 --api-version=2 --accept-multiclient"
# cmd = "go build -o ./bin/${SERVICE_NAME} ./services/${SERVICE_NAME}/app/. && dlv exec ./bin/${SERVICE_NAME} --headless --continue --listen=:40000 --api-version=2 --accept-multiclient"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
Expand All @@ -19,8 +19,8 @@ tmp_dir = "build"
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
poll = true
poll_interval = 2000
post_cmd = []
pre_cmd = []
rerun = false
Expand Down
8 changes: 5 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
# container here (e.g., local bin artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/
Expand Down Expand Up @@ -30,5 +30,7 @@
**/values.dev.yaml
LICENSE
README.md
Dockerfile*
compose*
README.Docker.md
.run
.github
*.toml
27 changes: 26 additions & 1 deletion .github/workflows/dockerize-and-deploy-app_development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,32 @@ on:
- development

jobs:
Define-services-matrix:
runs-on: ubuntu-latest
environment: development
outputs:
services-matrix: ${{ steps.generate-matrix.outputs.matrix }}
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Generate matrix data
id: generate-matrix
run: |
./.github/workflows/scripts/generate-services-matrix.sh
shell: bash

- name: Output matrix data
run: |
echo "Matrix: ${{ steps.generate-matrix.outputs.matrix }}"
Build-image:
needs: Define-services-matrix
runs-on: ubuntu-latest
environment: development
strategy:
matrix:
service: ${{ fromJSON(needs.Define-services-matrix.outputs.services-matrix) }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
Expand All @@ -31,7 +54,9 @@ jobs:
with:
file: Dockerfile-development
push: true
tags: ${{ vars.DOCKERHUB_USERNAME }}/utctss-mss:dev-v1
tags: ${{ vars.DOCKERHUB_USERNAME }}/utconnect-${{ matrix.service.service-name }}:dev-v1
build-args: |
service_name=${{ matrix.service.service-name }}
# Deploy-app:
# needs:
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/scripts/generate-services-matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Set the root directory where the services are located
SERVICES_DIR="./services"

# Initialize an empty matrix array
MATRIX="["

# Loop through each subfolder in the 'services' directory
for SERVICE in $(ls -d ${SERVICES_DIR}/*/); do
# Extract the folder name without the path
SERVICE_NAME=$(basename $SERVICE)

# Append to the matrix JSON object
MATRIX+="{\"service-name\": \"$SERVICE_NAME\"},"
done

# Remove the last comma and close the JSON array
MATRIX=${MATRIX%,}
MATRIX+="]"

# Output the matrix in the format that GitHub Actions expects using Environment Files
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ go.work.sum

#ide/editor
#ide
.idea
.idea/*
!.idea/runConfigurations
.vscode

.env*
Expand Down
6 changes: 6 additions & 0 deletions .run/Debug remote.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Debug remote" type="GoRemoteDebugConfigurationType" factoryName="Go Remote" port="40000">
<option name="disconnectOption" value="ASK" />
<method v="2" />
</configuration>
</component>
21 changes: 21 additions & 0 deletions .run/build image-dev.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build image-dev" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="imageTag" value="utconnect-docs:dev-v1" />
<option name="buildArgs">
<list>
<DockerEnvVarImpl>
<option name="name" value="service_name" />
<option name="value" value="docs" />
</DockerEnvVarImpl>
</list>
</option>
<option name="buildCliOptions" value="--progress=plain" />
<option name="buildOnly" value="true" />
<option name="sourceFilePath" value="Dockerfile-development" />
</settings>
</deployment>
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="compose-local-single-service.yaml[adminer, app-service, postgres]: Compose Deployment" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
<deployment type="docker-compose.yml">
<settings>
<option name="composeProjectName" value="utconnect-go_single-local" />
<option name="envFilePath" value="" />
<option name="commandLineOptions" value="--build" />
<option name="services">
<list>
<option value="adminer" />
<option value="app-service" />
<option value="postgres" />
</list>
</option>
<option name="sourceFilePath" value="../UTCTSS-microservices/compose-local-single-service.yaml" />
<option name="upDetach" value="false" />
<option name="upRemoveOrphans" value="true" />
<option name="upRenewAnonVolumes" value="true" />
</settings>
</deployment>
<method v="2">
<option name="RunConfigurationTask" enabled="true" run_configuration_name="utconnect common setup" run_configuration_type="ShConfigurationType" />
</method>
</configuration>
</component>
4 changes: 2 additions & 2 deletions .run/docker compose local.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration default="false" name="docker compose local" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
<deployment type="docker-compose.yml">
<settings>
<option name="composeProjectName" value="utctss-mss-local" />
<option name="composeProjectName" value="utconnect-go_local" />
<option name="envFilePath" value="" />
<option name="envVars">
<list>
Expand All @@ -18,12 +18,12 @@
</option>
<option name="sourceFilePath" value="compose-local.yaml" />
<option name="upDetach" value="false" />
<option name="upForceRecreate" value="true" />
<option name="upRemoveOrphans" value="true" />
<option name="upRenewAnonVolumes" value="true" />
</settings>
</deployment>
<method v="2">
<option name="RunConfigurationTask" enabled="true" run_configuration_name="script build local docker image" run_configuration_type="ShConfigurationType" />
<option name="RunConfigurationTask" enabled="true" run_configuration_name="utconnect common setup" run_configuration_type="ShConfigurationType" />
</method>
</configuration>
Expand Down
2 changes: 1 addition & 1 deletion .run/script build local docker image.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="script build local docker image" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="docker build -f Dockerfile-local -t utctss-mss:v1 ." />
<option name="SCRIPT_TEXT" value="docker build -f Dockerfile-local -t utconnect-go:v1 ." />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
Expand Down
17 changes: 17 additions & 0 deletions .run/utconnect common setup.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="utconnect common setup" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="false" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/../../../projects/utconnect/utconnect-common-setup/create_network.sh" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/../../../projects/utconnect/utconnect-common-setup" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="false" />
<option name="INTERPRETER_PATH" value="C:/Program Files/Git/git-bash.exe" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="true" />
<envs />
<method v="2" />
</configuration>
</component>
14 changes: 10 additions & 4 deletions Dockerfile-development
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# syntax=docker/dockerfile:1
FROM golang:1.22-alpine3.20

ARG service_name

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download
RUN go install github.com/go-swagger/go-swagger/cmd/[email protected]

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -o ./build/migrationtool ./database/migrations/tool/.
RUN CGO_ENABLED=0 GOOS=linux go build -o ./build/main ./app/.
RUN CGO_ENABLED=0 GOOS=linux go build -o ./core/database/migrations/tool/bin/migration-tool ./core/database/migrations/tool/main/.
RUN CGO_ENABLED=0 GOOS=linux go build -o ./bin/$service_name ./services/$service_name/app/.

#RUN addgroup -g 1000 appgroup
#RUN adduser -D -u 1000 appuser -G appgroup
#USER appuser

ENTRYPOINT ["./build/main"]
ENV SERVICE_NAME=$service_name

ENTRYPOINT ["sh", "-c", "./bin/$SERVICE_NAME"]
6 changes: 3 additions & 3 deletions Dockerfile-local
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# syntax=docker/dockerfile:1
FROM golang:1.22-alpine3.20

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download
RUN go install github.com/air-verse/[email protected]
RUN go install github.com/go-delve/delve/cmd/[email protected]
RUN go install github.com/go-swagger/go-swagger/cmd/[email protected]

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -o ./build/migrationtool ./database/migrations/tool/.
RUN CGO_ENABLED=0 GOOS=linux go build -o ./core/database/migrations/tool/bin/migration-tool ./core/database/migrations/tool/main/.

CMD ["air", "-d"]
71 changes: 0 additions & 71 deletions app/main.go

This file was deleted.

File renamed without changes.
6 changes: 6 additions & 0 deletions common/colors-logger.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package common

import "fmt"

const (
Reset = "\033[0m"
Red = "\033[31m"
Expand All @@ -10,3 +12,7 @@ const (
Cyan = "\033[36m"
White = "\033[37m"
)

func ConsoleLogBlue(value any) {
fmt.Printf(Blue+"%+v"+Reset+"\n", value)
}
Loading

0 comments on commit a08e8d3

Please sign in to comment.