Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync : dev to main #47

Merged
merged 18 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
45 changes: 45 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main src/main.go"
delay = 0
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true

32 changes: 32 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/

**/.DS_Store
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
67 changes: 67 additions & 0 deletions .github/workflows/release-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Deploy to Staging

on:
workflow_dispatch:
push:
branches:
- develop
- yash/group

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: staging

env:
AWS_REGION: ${{ vars.AWS_REGION }}
ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }}
ECS_SERVICE: ${{ vars.ECS_SERVICE }}
ECS_CLUSTER: ${{ vars.ECS_CLUSTER }}
ECS_TASK_DEFINITION: ${{ vars.ECS_TASK_DEFINITION }}
CONTAINER_NAME: ${{ vars.CONTAINER_NAME }}

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

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition wisee-backend --query taskDefinition > task-definition.json

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -f docker/release.dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"

- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: false
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Tests

on:
pull_request:
branches: ["*"]

jobs:
tests:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: wisee_core_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

name: Run tests
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: "./go.mod"

- run: go version

- name: Copy Env
run: cp ./environments/test.env .env

- name: Run Unit tests
run: make test_unit

- name: Run Integration tests
run: make test_integration
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build
TODO
tmp
.env
.env.local
bin
database/pgdata
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker"
]
}
29 changes: 29 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
/**
Editor rules
------------
*/
"editor.formatOnSave": true,
"editor.tabSize": 4,
"prettier.tabWidth": 4,
"prettier.printWidth": 120,
"editor.rulers": [
{
"column": 120
}
],
/**
Formatters
------------
*/
"editor.defaultFormatter": "esbenp.prettier-vscode",
/**
New Lines
------------
*/
"files.eol": "\n",
"files.insertFinalNewline": true,
"[go]": {
"editor.defaultFormatter": "golang.go"
},
}
109 changes: 109 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
BINARY_NAME := "wisee"
DEV_DATABASE_URL := "postgres://postgres:postgres@localhost:5432/wisee_core?sslmode=disable"

ARCH := $(or $(GOARCH),$(shell uname -m))
OS := $(or $(GOOS),$(shell uname))

ifneq (,$(filter $(OS),Darwin darwin MacOS macos))
OS := darwin
else ifneq (,$(filter $(OS),Linux linux))
OS := linux
else
OS := windows
endif

ifeq ($(ARCH),x86_64)
ARCH := amd64
else ifeq ($(ARCH),i386)
ARCH := 386
else ifeq ($(ARCH),aarch64)
ARCH := arm64
endif

build:
@echo "Building $(OS) $(ARCH) binary..."
@GOOS=$(OS) GOARCH=$(ARCH) CGO_ENABLED=0 go build $(ARGS) -o "bin/$(BINARY_NAME)" ./src

test_unit:
@echo "Running tests..."
@@GOOS=$(OS) GOARCH=$(ARCH) ENV=test go test -race -covermode=atomic -v -coverpkg=./src/... ./tests/unit/... ./src/...

test_integration:
@echo "Running tests..."
@@GOOS=$(OS) GOARCH=$(ARCH) ENV=test go test -race -covermode=atomic -v -coverpkg=./src/... ./tests/integration/... ./src/...

test: test_unit test_integration

clean:
@echo "Cleaning..."
@go clean
@rm -rf bin/*

# Live Reload
watch:
@if command -v air > /dev/null; then \
air; \
echo "Watching...";\
else \
read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
go install github.com/cosmtrek/air@latest; \
air; \
echo "Watching...";\
else \
echo "You chose not to install air. Exiting..."; \
exit 1; \
fi; \
fi

# Up all migrations
migrate-all-up:
@if command -v migrate > /dev/null; then \
migrate -database $(DEV_DATABASE_URL) -path ./database/migrations up; \
else \
echo "Golang Migrate cli is not installed on your machine. Exiting..."; \
exit 1; \
fi

# Drop all migrations when in development
migrate-all-down:
@if command -v migrate > /dev/null; then \
migrate -database $(DEV_DATABASE_URL) -path ./database/migrations down; \
else \
echo "Golang Migrate cli is not installed on your machine. Exiting..."; \
exit 1; \
fi

# Setup Databse and PGAdmin
docker-run:
@if command -v docker > /dev/null; then \
docker-compose -f docker/dev-docker-compose.yaml up -d; \
else \
echo "Docker is not installed on your machine. Exiting..."; \
exit 1; \
fi

# Down Database and PGAdmin
docker-down:
@if command -v docker > /dev/null; then \
docker-compose -f docker/dev-docker-compose.yaml down; \
else \
echo "Docker is not installed on your machine. Exiting..."; \
exit 1; \
fi

# Setup development environment
setup:
@echo "--- Copying .env files ---"
@cp environments/dev.env .env

@echo "--- Setting up docker ---"
@make docker-run

@echo "--- Waiting for database to setup ---"
@sleep 3

@echo "--- Running all migrations ---"
@make migrate-all-up
@echo "\n"
@echo "Setup complete. To start the server, run 'make watch'"
Loading
Loading