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

feat: first version of driver #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
## code changes will send PR to following users

<!-- TODO Add code owners for new repo here -->
<!-- * @ -->
* @pablocampogo
* @rem1niscence
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build & Test
name: Lint & Test

on:
pull_request:
Expand All @@ -9,34 +9,25 @@ on:
branches:
- main
- staging
workflow_dispatch:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Check out code
uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3

- name: Run Golang ci Action
uses: golangci/golangci-lint-action@v3

test:
build:
name: Test
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Check out code
uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3

- name: Set up cache
uses: actions/cache@v2
Expand All @@ -48,5 +39,8 @@ jobs:
restore-keys: |
${{ runner.os }}-go-

- name: Build the Docker test stack
run: make test_env_up

- name: Run Unit tests
run: go test ./...
67 changes: 0 additions & 67 deletions .github/workflows/production-us-west-2.yml

This file was deleted.

75 changes: 75 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Tag & Go List

on:
workflow_run:
workflows: ["Lint & Test"]
branches: [main]
types:
- completed

jobs:
release:
runs-on: ubuntu-22.04
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
version: ${{ steps.semantic.outputs.release-version }}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3

- name: Set up cache
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Tag
uses: codfish/[email protected]
id: semantic
with:
branches: |
['main']
tag_format: "v${version}"
additional_packages: |
['@semantic-release/commit-analyzer']
plugins: |
['@semantic-release/commit-analyzer']
- name: Go List
if: steps.semantic.outputs.new-release-published == 'true'
run: GOPROXY=proxy.golang.org go list -m github.com/pokt-foundation/data-warehouse-db@v${{ steps.semantic.outputs.release-version }}

docker:
if: needs.release.outputs.version
name: Docker Build & Push
needs: [release]
timeout-minutes: 15
runs-on: ubuntu-22.04
environment: CI

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker images
uses: docker/build-push-action@v3
with:
push: true
context: .
file: ./Dockerfile
tags: |
pocketfoundation/test-data-warehouse-postgres:latest
pocketfoundation/test-data-warehouse-postgres:${{ needs.release.outputs.version }}
17 changes: 3 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
FROM golang:1.18-alpine AS builder
RUN apk add --no-cache git
WORKDIR /go/src/github.com/pokt-foundation
# This Dockerfile used to build the image used for testing TxDB
FROM postgres:14.3

# TODO Replace `backend-go-repo-template` with repo name
COPY . /go/src/github.com/pokt-foundation/backend-go-repo-template

WORKDIR /go/src/github.com/pokt-foundation/backend-go-repo-template
RUN CGO_ENABLED=0 GOOS=linux go build -a -o bin ./main.go

FROM alpine:3.16.0
WORKDIR /app
COPY --from=builder /go/src/github.com/pokt-foundation/backend-go-repo-template/bin ./

ENTRYPOINT ["/app/bin"]
COPY ./postgres-driver/sqlc/schema.sql /docker-entrypoint-initdb.d/
20 changes: 6 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
build:
# TODO Replace `backend-go-repo-template` with repo name
CGO_ENABLED=0 GOOS=linux go build -a -o bin/backend-go-repo-template ./main.go
make: gen_sql

# TODO If repo does not use a Docker Compose test environment these can be removed
gen_sql:
sqlc generate -f ./postgres-driver/sqlc/sqlc.yaml
test_driver: test_env_up run_driver_tests test_env_down
test_env_up:
docker-compose -f ./docker-compose.test.yml up -d --remove-orphans --build;
sleep 2;
test_env_down:
docker-compose -f ./docker-compose.test.yml down --remove-orphans -v
run_unit_tests:
go test ./... -short
run_e2e_tests:
-go test ./... -run E2E -count=1;
run_all_tests:
-go test ./... -count=1;

test_unit: test_env_up run_unit_tests test_env_down
test_e2e: test_env_up run_e2e_tests test_env_down
test: test_env_up run_all_tests test_env_down
run_driver_tests:
-go test ./... -run Test_RunPGDriverSuite -count=1 -v;

init-pre-commit:
wget https://github.com/pre-commit/pre-commit/releases/download/v2.20.0/pre-commit-2.20.0.pyz
Expand Down
19 changes: 3 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,13 @@
<big>Template repository for creating a new backend Go repo</big>
<div>
<br/>
<!-- TODO Replace `backend-go-repo-template` with repo name -->
<a href="https://github.com/pokt-foundation/backend-go-repo-template/pulse"><img src="https://img.shields.io/github/last-commit/pokt-foundation/backend-go-repo-template.svg"/></a>
<a href="https://github.com/pokt-foundation/backend-go-repo-template/pulls"><img src="https://img.shields.io/github/issues-pr/pokt-foundation/backend-go-repo-template.svg"/></a>
<a href="https://github.com/pokt-foundation/backend-go-repo-template/issues"><img src="https://img.shields.io/github/issues-closed/pokt-foundation/backend-go-repo-template.svg"/></a>
<a href="https://github.com/pokt-foundation/data-warehouse-db/pulse"><img src="https://img.shields.io/github/last-commit/pokt-foundation/data-warehouse-db.svg"/></a>
<a href="https://github.com/pokt-foundation/data-warehouse-db/pulls"><img src="https://img.shields.io/github/issues-pr/pokt-foundation/data-warehouse-db.svg"/></a>
<a href="https://github.com/pokt-foundation/data-warehouse-db/issues"><img src="https://img.shields.io/github/issues-closed/pokt-foundation/data-warehouse-db.svg"/></a>
</div>
</div>
<br/>

<!-- TODO Replace this section with a README.md describing the new repo -->

# Instructions For a New Repo

1. Click the `Use this template` button, then click `Create a new repository` to create a new repo with the same file structure as this template.
2. There are a number of comments marked with `TODO` throughout the repo; go through them all and update as appropriate, then remove the `TODO` comment.
3. Replace all instances of `backend-go-repo-template` with the name of the new repo.
4. Update this `README.md`
5. Profit.

<!-- TODO Update the nelow section with development instructions (leave the pre-commit section in place) -->

# Development

## Pre-Commit Installation
Expand Down
18 changes: 15 additions & 3 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# This Dockerfile only used for setting up a local Dockerized test environment for running E2E tests.
# TODO If repo does not use a Docker Compose test environment this file can be removed
# This Dockerfile only used for setting up a local Postgres DB for testing
version: "3"

services:
# TODO - declare any services needed to run E2E tests here
test-database:
build:
context: .
container_name: test-database
restart: always
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: pgpassword
POSTGRES_DB: postgres
healthcheck:
test: pg_isready -U postgres
interval: 5s
retries: 3
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// TODO - rename repository
module github.com/pokt-foundation/backend-go-repo-template
module github.com/pokt-foundation/data-warehouse-db

go 1.18

require (
github.com/pokt-foundation/utils-go v0.2.4
github.com/sirupsen/logrus v1.9.0
github.com/lib/pq v1.10.7
github.com/stretchr/testify v1.8.2
)

require (
github.com/joho/godotenv v1.4.0 // indirect
golang.org/x/sys v0.0.0-20220913175220-63ea55921009 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
21 changes: 10 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pokt-foundation/utils-go v0.2.4 h1:1OntN55cxnbvpRjI7g5ndk9duZ9B7SPwe0EJsHKXZ7g=
github.com/pokt-foundation/utils-go v0.2.4/go.mod h1:c92FV9S9qY4PEyeOv4fGkI9FTZSv8oh1MiARGC+BC2E=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220913175220-63ea55921009 h1:PuvuRMeLWqsf/ZdT1UUZz0syhioyv1mzuFZsXs4fvhw=
golang.org/x/sys v0.0.0-20220913175220-63ea55921009/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading