Skip to content

Commit

Permalink
Merge pull request #42 from mpiorowski/feature/move-postgres
Browse files Browse the repository at this point in the history
Added utils as the only service using postgres
  • Loading branch information
mpiorowski authored Jun 16, 2023
2 parents f8505de + 5435b11 commit 65a7244
Show file tree
Hide file tree
Showing 121 changed files with 9,937 additions and 2,227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Deploy Notes Rust
on:
push:
branches:
- release-notes/**
- release-notes-rust/**
workflow_call:
secrets:
GCP_CREDENTIALS:
Expand All @@ -16,7 +16,7 @@ env:
PROJECT_ID: rusve-384620
REPOSITORY: rusve-repo
DATABASE: rusve-db
SERVICE: notes
SERVICE: notes-rust
REGION: europe-north1
ENV: production
DATABASE_URL: ${{ secrets.DATABASE_URL }}/notes?require_ssl=true
Expand All @@ -28,7 +28,7 @@ permissions:

jobs:
lint:
uses: ./.github/workflows/lint-notes.yml
uses: ./.github/workflows/lint-notes-rust.yml
deploy:
needs:
- lint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Deploy Users Rust
on:
push:
branches:
- release-users/**
- release-users-rust/**
workflow_call:
secrets:
GCP_CREDENTIALS:
Expand All @@ -18,7 +18,7 @@ env:
PROJECT_ID: rusve-384620
REPOSITORY: rusve-repo
DATABASE: rusve-db
SERVICE: users
SERVICE: users-rust
REGION: europe-north1
ENV: production
BUCKET: rusve-bucket
Expand All @@ -32,7 +32,7 @@ permissions:

jobs:
lint:
uses: ./.github/workflows/lint-users.yml
uses: ./.github/workflows/lint-users-rust.yml
deploy:
needs:
- lint
Expand Down Expand Up @@ -66,7 +66,5 @@ jobs:
env_vars: |
ENV=${{ env.ENV }}
DATABASE_URL=${{ env.DATABASE_URL }}
SENDGRID_API_KEY=${{ env.SENDGRID_API_KEY }}
BUCKET=${{ env.BUCKET }}
- name: Show Output
run: echo ${{ steps.deploy.outputs.url }}
72 changes: 72 additions & 0 deletions .github/workflows/deploy-utils-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Deploy Users Go

on:
push:
branches:
- release-users-go/**
workflow_call:
secrets:
GCP_CREDENTIALS:
required: true
DATABASE_URL:
required: true
SENDGRID_API_KEY:
required: true

env:
GAR_LOCATION: europe-north1
PROJECT_ID: rusve-384620
REPOSITORY: rusve-repo
DATABASE: rusve-db
SERVICE: users-go
REGION: europe-north1
ENV: production
BUCKET: rusve-bucket
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}&dbname=users
# DATABASE_URL=postgresql:///?dbname=${{ env.SERVICE }}&host=/cloudsql/${{ env.PROJECT_ID }}:${{ env.REGION }}:${{ env.DATABASE }}&user=postgres&password=${{ secrets.DB_PASS }}

permissions:
contents: read
id-token: write

jobs:
lint:
uses: ./.github/workflows/lint-users-go.yml
deploy:
needs:
- lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Google Auth
id: auth
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GCP_CREDENTIALS }}"
- name: Docker Auth
id: docker-auth
uses: docker/login-action@v2
with:
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCP_CREDENTIALS }}
- name: Build and Push Container
run: |-
docker build -f ./service-users-go/Dockerfile -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}" ./service-users-go
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}"
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ env.SERVICE }}
region: ${{ env.REGION }}
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}
env_vars: |
ENV=${{ env.ENV }}
DATABASE_URL=${{ env.DATABASE_URL }}
SENDGRID_API_KEY=${{ env.SENDGRID_API_KEY }}
BUCKET=${{ env.BUCKET }}
- name: Show Output
run: echo ${{ steps.deploy.outputs.url }}
70 changes: 70 additions & 0 deletions .github/workflows/deploy-utils-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Deploy Users Rust

on:
push:
branches:
- release-users-rust/**
workflow_call:
secrets:
GCP_CREDENTIALS:
required: true
DATABASE_URL:
required: true
SENDGRID_API_KEY:
required: true

env:
GAR_LOCATION: europe-north1
PROJECT_ID: rusve-384620
REPOSITORY: rusve-repo
DATABASE: rusve-db
SERVICE: users-rust
REGION: europe-north1
ENV: production
BUCKET: rusve-bucket
DATABASE_URL: ${{ secrets.DATABASE_URL }}&dbname=users
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
# DATABASE_URL=postgresql:///?dbname=${{ env.SERVICE }}&host=/cloudsql/${{ env.PROJECT_ID }}:${{ env.REGION }}:${{ env.DATABASE }}&user=postgres&password=${{ secrets.DB_PASS }}

permissions:
contents: read
id-token: write

jobs:
lint:
uses: ./.github/workflows/lint-users-rust.yml
deploy:
needs:
- lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Google Auth
id: auth
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GCP_CREDENTIALS }}"
- name: Docker Auth
id: docker-auth
uses: docker/login-action@v2
with:
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCP_CREDENTIALS }}
- name: Build and Push Container
run: |-
docker build -f ./service-${{ env.SERVICE }}/Dockerfile -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}" ./service-${{ env.SERVICE }}
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}"
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ env.SERVICE }}
region: ${{ env.REGION }}
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.SERVICE }}:${{ github.sha }}
env_vars: |
ENV=${{ env.ENV }}
DATABASE_URL=${{ env.DATABASE_URL }}
- name: Show Output
run: echo ${{ steps.deploy.outputs.url }}
16 changes: 13 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@ jobs:
PUBLIC_AUTH_DOMAIN: ${{ secrets.PUBLIC_AUTH_DOMAIN }}
SERVICE_ACCOUNT: ${{ secrets.SERVICE_ACCOUNT }}
STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
deploy-users:
uses: ./.github/workflows/deploy-users.yml
deploy-users-rust:
uses: ./.github/workflows/deploy-users-rust.yml
secrets:
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
deploy-users-go:
uses: ./.github/workflows/deploy-users-go.yml
secrets:
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
deploy-utils-rust:
uses: ./.github/workflows/deploy-utils-rust.yml
secrets:
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
deploy-utils-go:
uses: ./.github/workflows/deploy-utils-go.yml
secrets:
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
Expand Down
14 changes: 5 additions & 9 deletions .github/workflows/lint-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: "18.x"
- name: Install dependencies
run: npm i
- name: Copy env file
run: cp .env.example .env
- name: Run build
run: npm run build
- name: Run lint
run:
npm run lint
- run: cp .env.example .env
- run: npm i -g pnpm
- run: pnpm i
- run: pnpm run build
- run: pnpm run lint
#- name: Annotate Pull Request
# uses: actions/github-script@v3
# with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./service-notes
working-directory: ./service-notes-rust
steps:
- uses: actions/checkout@v3
- run: RUSTFLAGS="--cfg uuid_unstable" cargo clippy
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./service-users
working-directory: ./service-users-rust
steps:
- uses: actions/checkout@v3
- run: RUSTFLAGS="--cfg uuid_unstable" cargo clippy
20 changes: 20 additions & 0 deletions .github/workflows/lint-utils-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint Utils Go
on:
workflow_call:

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.20"
cache: false
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
working-directory: ./service-utils-go
args: --skip-dirs=proto --timeout=3m
16 changes: 16 additions & 0 deletions .github/workflows/lint-utils-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint Utils Rust
on:
workflow_call:

env:
RUSTFLAGS: "-Dwarnings"

jobs:
lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./service-utils-rust
steps:
- uses: actions/checkout@v3
- run: RUSTFLAGS="--cfg uuid_unstable" cargo clippy
12 changes: 8 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ permissions:
jobs:
lint-client:
uses: ./.github/workflows/lint-client.yml
lint-users:
uses: ./.github/workflows/lint-users.yml
lint-users-rust:
uses: ./.github/workflows/lint-users-rust.yml
lint-users-go:
uses: ./.github/workflows/lint-users-go.yml
lint-notes:
uses: ./.github/workflows/lint-notes.yml
lint-utils-rust:
uses: ./.github/workflows/lint-utils-rust.yml
lint-utils-go:
uses: ./.github/workflows/lint-utils-go.yml
lint-notes-rust:
uses: ./.github/workflows/lint-notes-rust.yml
lint-notes-go:
uses: ./.github/workflows/lint-notes-go.yml
2 changes: 2 additions & 0 deletions client/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ DOMAIN="http://localhost:3000"

URI_USERS_RUST="service-users-rust"
URI_USERS_GO="service-users-go"
URI_UTILS_RUST="service-utils-rust"
URI_UTILS_GO="service-utils-go"
URI_NOTES_RUST="service-notes-rust"
URI_NOTES_GO="service-notes-go"

Expand Down
16 changes: 16 additions & 0 deletions client/src/lib/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
ENV,
URI_NOTES_RUST,
URI_NOTES_GO,
URI_UTILS_RUST,
URI_UTILS_GO,
URI_USERS_RUST,
URI_USERS_GO,
} from "$env/static/private";
Expand All @@ -30,6 +32,20 @@ export const usersGoClient = new proto.proto.UsersService(
: credentials.createInsecure(),
);

export const utilsRustClient = new proto.proto.UtilsService(
URI_UTILS_RUST,
ENV === "production"
? credentials.createSsl()
: credentials.createInsecure(),
);

export const utilsGoClient = new proto.proto.UtilsService(
URI_UTILS_GO,
ENV === "production"
? credentials.createSsl()
: credentials.createInsecure(),
);

export const notesRustClient = new proto.proto.NotesService(
URI_NOTES_RUST,
ENV === "production"
Expand Down
Loading

0 comments on commit 65a7244

Please sign in to comment.