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

Add queue, db migrations, proto and api. fix past unit tests. update the env files. #23

Merged
merged 1 commit into from
Sep 4, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 46 additions & 46 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
- name: Check out code
uses: actions/checkout@v4

- name: Install kubectl
uses: azure/setup-kubectl@v4
with:
version: 'v1.30.3'
id: install
# - name: Install kubectl
# uses: azure/setup-kubectl@v4
# with:
# version: 'v1.30.3'
# id: install

- name: Get custom info
id: custome-var
Expand All @@ -31,49 +31,49 @@ jobs:
echo "build-time=$(TZ=Asia/Taipei date +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_OUTPUT
echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT

- 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: 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: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
# - name: Login to Amazon ECR
# id: login-ecr
# uses: aws-actions/amazon-ecr-login@v2

- name: Load secrets and save to app.env
run: aws secretsmanager get-secret-value --secret-id go-todolist-grpc --query SecretString --output text | jq -r 'to_entries|map("\(.key)=\(.value)")|.[]' > app.env
# - name: Load secrets and save to app.env
# run: aws secretsmanager get-secret-value --secret-id go-todolist-grpc --query SecretString --output text | jq -r 'to_entries|map("\(.key)=\(.value)")|.[]' > app.env

- name: Build, tag, and push docker image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: go-todolist-grpc
IMAGE_TAG: ${{ github.sha }}
BUILD_VERSION: ${{ steps.custome-var.outputs.tag-name }}
COMMIT_HASH: ${{ steps.custome-var.outputs.short-sha }}
BUILD_TIME: ${{ steps.custome-var.outputs.build-time }}
BRANCH: ${{ steps.custome-var.outputs.branch }}
run: |
docker build \
--build-arg BUILD_VERSION="$BUILD_VERSION" \
--build-arg COMMIT_HASH="$COMMIT_HASH" \
--build-arg BUILD_TIME="$BUILD_TIME" \
--build-arg BRANCH="$BRANCH" \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker push -a $ECR_REGISTRY/$ECR_REPOSITORY
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$BUILD_VERSION" >> $GITHUB_OUTPUT
# - name: Build, tag, and push docker image to Amazon ECR
# id: build-image
# env:
# ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
# ECR_REPOSITORY: go-todolist-grpc
# IMAGE_TAG: ${{ github.sha }}
# BUILD_VERSION: ${{ steps.custome-var.outputs.tag-name }}
# COMMIT_HASH: ${{ steps.custome-var.outputs.short-sha }}
# BUILD_TIME: ${{ steps.custome-var.outputs.build-time }}
# BRANCH: ${{ steps.custome-var.outputs.branch }}
# run: |
# docker build \
# --build-arg BUILD_VERSION="$BUILD_VERSION" \
# --build-arg COMMIT_HASH="$COMMIT_HASH" \
# --build-arg BUILD_TIME="$BUILD_TIME" \
# --build-arg BRANCH="$BRANCH" \
# -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
# docker push -a $ECR_REGISTRY/$ECR_REPOSITORY
# echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$BUILD_VERSION" >> $GITHUB_OUTPUT

- name: Update kube config
run: aws eks update-kubeconfig --name go-todolist-grpc-eks --region ap-northeast-1
# - name: Update kube config
# run: aws eks update-kubeconfig --name go-todolist-grpc-eks --region ap-northeast-1

- name: Deploy image to Amazon EKS
run: |
kubectl apply -f eks/aws-auth.yaml
kubectl apply -f eks/deployment.yaml
kubectl apply -f eks/service.yaml
kubectl apply -f eks/issuer.yaml
kubectl apply -f eks/ingress-nginx.yaml
kubectl apply -f eks/ingress-http.yaml
kubectl apply -f eks/ingress-grpc.yaml
# - name: Deploy image to Amazon EKS
# run: |
# kubectl apply -f eks/aws-auth.yaml
# kubectl apply -f eks/deployment.yaml
# kubectl apply -f eks/service.yaml
# kubectl apply -f eks/issuer.yaml
# kubectl apply -f eks/ingress-nginx.yaml
# kubectl apply -f eks/ingress-http.yaml
# kubectl apply -f eks/ingress-grpc.yaml
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DOCKER = docker compose exec server
DOCKER_HOST=db
TEST_DB=test_db
YMD = _$$(date +'%Y%m%d')
number?=3
number ?= $(shell ls -1 ./internal/migrations/*.up.sql 2>/dev/null | wc -l)
table :=
LOG_DIRS := internal/pkg/db/target internal/service/target

Expand All @@ -27,10 +27,18 @@ migrate-create:

# make migrate-up number=x
migrate-up:
$(DOCKER) migrate -path ./internal/migrations -database "$(DB)://$(DB_USER):$(DB_PASS)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=verify-full&sslrootcert=./internal/config/certs/rds-ca-2019-root.pem" up $(number)
$(DOCKER) migrate -path ./internal/migrations -database "$(DB)://$(DB_USER):$(DB_PASS)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable" up $(number)

# make migrate-down number=x
migrate-down:
$(DOCKER) migrate -path ./internal/migrations -database "$(DB)://$(DB_USER):$(DB_PASS)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable" down $(number)

# make migrate-aws-up number=x
migrate-aws-up:
$(DOCKER) migrate -path ./internal/migrations -database "$(DB)://$(DB_USER):$(DB_PASS)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=verify-full&sslrootcert=./internal/config/certs/rds-ca-2019-root.pem" up $(number)

# make migrate-aws-down number=x
migrate-aws-down:
$(DOCKER) migrate -path ./internal/migrations -database "$(DB)://$(DB_USER):$(DB_PASS)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=verify-full&sslrootcert=./internal/config/certs/rds-ca-2019-root.pem" down $(number)

# make migrate-test-up number=x
Expand Down Expand Up @@ -63,6 +71,7 @@ go-test:
go test -v internal/pkg/util/jwt_test.go -json > ./target/log/jwt_test$(YMD).log; \
go test -v internal/pkg/util/random_test.go -json > ./target/log/random_test$(YMD).log; \
go test -v internal/pkg/util/th_test.go -json > ./target/log/th_test$(YMD).log; \
go test -v internal/pkg/util/util_test.go -json > ./target/log/util_test$(YMD).log; \
go test -v internal/model/mod_user_test.go -json > ./target/log/mod_user_test$(YMD).log; \
go test -v internal/service/s_user_test.go -json > ./target/log/s_user_test$(YMD).log; \
go test -v internal/model/mod_category_test.go -json > ./target/log/mod_category_test$(YMD).log; \
Expand Down
156 changes: 148 additions & 8 deletions api/pb/model.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading