Skip to content

Commit

Permalink
Merge pull request #27 from kazhuravlev/ka/cicd
Browse files Browse the repository at this point in the history
Improve gh wf
  • Loading branch information
kazhuravlev authored Dec 18, 2024
2 parents 4ff0c3c + aa017e1 commit b73c15a
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 42 deletions.
9 changes: 4 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*
!go.mod
!go.sum
!cmd
!internal
!pkg
!cmd/
!internal/
!.toolset*
!go.*
56 changes: 56 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Database Gateway provides access to servers with ACL for safe and restricted database interactions.
# Copyright (C) 2024 Kirill Zhuravlev
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

name: Release

on:
push:
tags: [ '*' ]

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup golang
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: true
id: go

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Release and Publish
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: '~> v2'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
23 changes: 14 additions & 9 deletions .github/workflows/main.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

name: Go
name: Test

on:
pull_request:
branches: ['main']
branches: [ 'main' ]
push:
tags: ['*']
branches: ['main']
tags: [ '*' ]
branches: [ 'main' ]

jobs:
build:
Expand All @@ -35,20 +36,24 @@ jobs:
- "macOS-latest"

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

- name: Set up Go ${{ matrix.go_version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go_version }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get dependencies
run: go mod download

- name: Build
run: |
go build -v -o /dev/null ./cmd/gateway
- name: Test
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...

Expand Down
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ linters:
- govet

linters-settings:
gomoddirectives:
replace-allow-list:
- github.com/auxten/postgresql-parser
varnamelen:
ignore-names:
- 'ok'
Expand Down
85 changes: 85 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Database Gateway provides access to servers with ACL for safe and restricted database interactions.
# Copyright (C) 2024 Kirill Zhuravlev
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

version: 2
before:
hooks:
- go mod tidy

builds:
- id: 'database-gateway'
binary: 'database-gateway'
main: ./cmd/gateway
ldflags:
- -s
- -w
- -X main.version={{.Summary}}
mod_timestamp: '{{ .CommitTimestamp }}'
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
# goarch:
# - amd64
# goarm:
# - 6
# - 7
# goamd64:
# - v2
# - v3
# goarm64:
# - v9.0
dockers:
- id: 'database-gateway'
goos: linux
goarch: amd64
ids:
- 'database-gateway'
image_templates:
- "kazhuravlev/database-gateway:latest"
- "kazhuravlev/database-gateway:{{ .Tag }}"
- "kazhuravlev/database-gateway:v{{ .Major }}"
- "kazhuravlev/database-gateway:v{{ .Major }}.{{ .Minor }}"
dockerfile: 'Dockerfile'
use: buildx
build_flag_templates:
- "--platform=linux/amd64"
brews:
- name: 'database-gateway'
goarm: "6"
goamd64: v3
repository:
owner: 'kazhuravlev'
name: 'homebrew-database-gateway'
branch: main
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
url_template: "https://github.com/kazhuravlev/database-gateway/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
commit_author:
name: goreleaserbot
email: kazhuravlev+goreleaserbot@fastmail.com
commit_msg_template: "Brew formula update for {{ .ProjectName }} version {{ .Tag }}"
homepage: "https://github.com/kazhuravlev/database-gateway"
description: "Safe access to production databases"
license: "GPL-3.0"
test: |
system "#{bin}/gateway help"
archives:
- name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
checksum:
name_template: 'checksums.txt'
snapshot:
version_template: "{{ incpatch .Version }}-next"
21 changes: 7 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

FROM golang:1.23 AS builder
FROM alpine:3.21

COPY go.mod .
COPY go.sum .
ENV WORKDIR=/workdir

RUN go mod download
RUN mkdir -p ${WORKDIR}

COPY . .
WORKDIR ${WORKDIR}

RUN env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /app/gateway ./cmd/gateway
VOLUME ${WORKDIR}

FROM alpine:3.20
ENTRYPOINT ["/bin/gateway"]

WORKDIR /app

COPY --from=builder /app/gateway /app/gateway

ENTRYPOINT ["/app/gateway"]

CMD ["run"]
COPY database-gateway /bin/gateway
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

[![Go Reference](https://pkg.go.dev/badge/github.com/kazhuravlev/database-gateway.svg)](https://pkg.go.dev/github.com/kazhuravlev/database-gateway)
[![License](https://img.shields.io/github/license/kazhuravlev/database-gateway?color=blue)](https://github.com/kazhuravlev/database-gateway/blob/master/LICENSE)
[![Build Status](https://github.com/kazhuravlev/database-gateway/actions/workflows/main.yml/badge.svg)](https://github.com/kazhuravlev/database-gateway/actions/workflows/main.yml)
[![Test Status](https://github.com/kazhuravlev/database-gateway/actions/workflows/test.yml/badge.svg)](https://github.com/kazhuravlev/database-gateway/actions/workflows/test.yml)
[![Release Status](https://github.com/kazhuravlev/database-gateway/actions/workflows/release.yml/badge.svg)](https://github.com/kazhuravlev/database-gateway/actions/workflows/release.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/kazhuravlev/database-gateway)](https://goreportcard.com/report/github.com/kazhuravlev/database-gateway)
[![codecov](https://codecov.io/gh/kazhuravlev/database-gateway/graph/badge.svg?token=DLOML3FTN1)](https://codecov.io/gh/kazhuravlev/database-gateway)

Expand Down
9 changes: 1 addition & 8 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ version: "3"
vars:
PROJECT_NAME: database-gateway
DEPS_COMPOSE_FILE: ./.cicd/local/docker-compose.yaml
DOCKER_IMAGE_NAME: kazhuravlev/database-gateway
DOCKER_IMAGE_NAME: database-gateway
GO_ENTRYPOINT: ./cmd/gateway
GIT_TAG:
sh: "gt t l -f tag"
Expand Down Expand Up @@ -148,10 +148,3 @@ tasks:
--platform linux/amd64 \
-t {{ .DOCKER_IMAGE_NAME }}:{{.GIT_TAG}} \
-f Dockerfile .
docker:push:
cmds:
- echo ">>> Docker push"
- docker tag {{ .DOCKER_IMAGE_NAME }}:{{.GIT_TAG}} {{ .DOCKER_IMAGE_NAME }}:latest
- docker push {{ .DOCKER_IMAGE_NAME }}:{{.GIT_TAG}}
- docker push {{ .DOCKER_IMAGE_NAME }}:latest
5 changes: 4 additions & 1 deletion cmd/gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ import (

const keyConfig = "config"

var version = "unknown-local-build"

func main() {
application := &cli.App{ //nolint:exhaustruct
Name: "dbgw",
Name: "gateway",
Version: version,
Flags: []cli.Flag{
&cli.StringFlag{ //nolint:exhaustruct
Aliases: []string{"c"},
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/labstack/gommon v0.4.2
github.com/lib/pq v1.10.9
github.com/oklog/ulid/v2 v2.1.0
github.com/pkg/errors v0.9.1
github.com/pressly/goose/v3 v3.23.1
github.com/stretchr/testify v1.10.0
github.com/urfave/cli/v2 v2.27.5
Expand Down Expand Up @@ -60,6 +59,7 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mfridman/interpolate v0.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand All @@ -84,3 +84,5 @@ require (
google.golang.org/protobuf v1.36.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/auxten/postgresql-parser => github.com/kazhuravlev/postgresql-parser v0.0.2
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ github.com/a-h/templ v0.2.793/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9I
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/auxten/postgresql-parser v1.0.1 h1:x+qiEHAe2cH55Kly64dWh4tGvUKEQwMmJgma7a1kbj4=
github.com/auxten/postgresql-parser v1.0.1/go.mod h1:Nf27dtv8EU1C+xNkoLD3zEwfgJfDDVi8Zl86gznxPvI=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
Expand Down Expand Up @@ -235,6 +233,8 @@ github.com/kazhuravlev/just v0.72.0 h1:S00MjK8WlvmDJL6glbwb8WLMlMj/hFWL13zZyuZ0v
github.com/kazhuravlev/just v0.72.0/go.mod h1:36D5y2JKFDztf3j3rC/EE9Vwhj5zT530nG5/iWc9dL0=
github.com/kazhuravlev/options-gen v0.33.2 h1:K4rHJXVkG1XGtg/IIXIpdPkOKCN30ZCqYzlohepLdz4=
github.com/kazhuravlev/options-gen v0.33.2/go.mod h1:wCFGkAThbEJhMo+dSV3m9giwPOdPyj5nLYfhkZfkF+Y=
github.com/kazhuravlev/postgresql-parser v0.0.2 h1:Qbpeow2TC+/0sOXjFU0jBeHJ2fWjsz6W2wRTZZ5BK2U=
github.com/kazhuravlev/postgresql-parser v0.0.2/go.mod h1:GTsgkqvxnxEQdckuOO6ocAL8Dg6Ve7gfOghD5knKZb0=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down Expand Up @@ -266,7 +266,6 @@ github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjS
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
Expand Down

0 comments on commit b73c15a

Please sign in to comment.