Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0c99b58

Browse filesBrowse files
Docker containerizing (#41)
* add actoins, dockerfile, golangci * 👷 try build and push * 💡 suggestions to readme * Fixing Typo Co-authored-by: Artem <32013768+art-frela@users.noreply.github.com> * 👷 add volume instruction to dockerfile Co-authored-by: Faisal Ali <fai28683@gmail.com>
1 parent dd8b0bc commit 0c99b58
Copy full SHA for 0c99b58

17 files changed

+363
-93
lines changed

‎.dockerignore

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build.sh
2+
LICENSE
3+
*.md

‎.github/workflows/ci.yml

Copy file name to clipboard
+68Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- master
7+
- docker-containerizing # for test, remove after pass
8+
jobs:
9+
tests:
10+
strategy:
11+
matrix:
12+
go-version: [1.16.x]
13+
os: [ubuntu-latest, macos-latest]
14+
runs-on: ${{ matrix.os }}
15+
steps:
16+
- name: Install Go
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: ${{ matrix.go-version }}
20+
21+
- name: Checkout code
22+
uses: actions/checkout@v2
23+
24+
- name: Restore Cache
25+
uses: actions/cache@v2
26+
with:
27+
path: ~/go/pkg/mod
28+
key: ${{ runner.os }}-v1-go-${{ hashFiles('**/go.sum') }}
29+
restore-keys: |
30+
${{ runner.os }}-v1-go-
31+
- name: Test
32+
run: go test ./... -race -cover
33+
34+
codecov:
35+
needs: tests
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v2
39+
with:
40+
fetch-depth: 2
41+
- uses: actions/setup-go@v2
42+
with:
43+
go-version: '1.16'
44+
- name: Run coverage
45+
run: go test -coverprofile=coverage.txt -covermode=atomic ./...
46+
- name: Upload coverage to Codecov
47+
run: bash <(curl -s https://codecov.io/bash)
48+
49+
push_to_registry:
50+
needs: [tests]
51+
name: Push docker image to GitHub Container Registry
52+
runs-on: ubuntu-latest
53+
steps:
54+
- name: Check out code
55+
uses: actions/checkout@v2
56+
- name: Login to GitHub Container Registry
57+
uses: docker/login-action@v1
58+
with:
59+
registry: ghcr.io
60+
username: ${{ github.repository_owner }}
61+
password: ${{ secrets.CR_PAT }}
62+
- name: Push to GitHub Packages
63+
uses: docker/build-push-action@v2
64+
with:
65+
push: true
66+
context: .
67+
file: ./build/Dockerfile
68+
tags: ghcr.io/art-frela/mock-data:latest

‎.github/workflows/test.yml

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: unit tests
2+
on:
3+
push:
4+
branches-ignore:
5+
- main
6+
- master
7+
jobs:
8+
tests:
9+
strategy:
10+
matrix:
11+
go-version: [1.15.x, 1.16.x]
12+
os: [ubuntu-latest, macos-latest]
13+
runs-on: ${{ matrix.os }}
14+
steps:
15+
- name: Install Go
16+
uses: actions/setup-go@v2
17+
with:
18+
go-version: ${{ matrix.go-version }}
19+
20+
- name: Checkout code
21+
uses: actions/checkout@v2
22+
23+
- name: Restore Cache
24+
uses: actions/cache@v2
25+
with:
26+
path: ~/go/pkg/mod
27+
key: ${{ runner.os }}-v1-go-${{ hashFiles('**/go.sum') }}
28+
restore-keys: |
29+
${{ runner.os }}-v1-go-
30+
- name: Test
31+
run: go test ./... -race -cover

‎.golangci.yml

Copy file name to clipboard
+99Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
run:
16+
# default: '1m'
17+
timeout: '5m'
18+
19+
# default: []
20+
build-tags:
21+
- 'all'
22+
23+
# default: []
24+
skip-dirs:
25+
- 'build'
26+
27+
# which files to skip: they will be analyzed, but issues from them
28+
# won't be reported. Default value is empty list, but there is
29+
# no need to include all autogenerated files, we confidently recognize
30+
# autogenerated files. If it's not please let us know.
31+
skip-files:
32+
- "_easyjson.go"
33+
- "_test.go"
34+
35+
# default: true
36+
skip-dirs-use-default: false
37+
38+
# default: ''
39+
modules-download-mode: 'readonly'
40+
41+
# default: false
42+
allow-parallel-runners: true
43+
44+
linters:
45+
enable:
46+
- 'asciicheck'
47+
- 'bodyclose'
48+
- 'deadcode'
49+
- 'depguard'
50+
- 'dogsled'
51+
- 'errcheck'
52+
- 'errorlint'
53+
- 'exportloopref'
54+
- 'gofmt'
55+
- 'goheader'
56+
- 'goimports'
57+
- 'golint'
58+
- 'gomodguard'
59+
- 'goprintffuncname'
60+
- 'gosec'
61+
- 'gosimple'
62+
- 'govet'
63+
- 'ineffassign'
64+
- 'makezero'
65+
- 'misspell'
66+
- 'noctx'
67+
- 'paralleltest'
68+
- 'prealloc'
69+
- 'predeclared'
70+
- 'scopelint'
71+
- 'sqlclosecheck'
72+
- 'staticcheck'
73+
- 'structcheck'
74+
- 'stylecheck'
75+
- 'typecheck'
76+
- 'unconvert'
77+
- 'unused'
78+
- 'varcheck'
79+
- 'whitespace'
80+
81+
issues:
82+
# default: []
83+
exclude:
84+
- '^S1023:' # staticcheck: redundant returns help with http handlers
85+
- '^SA3000:' # staticcheck: not required in Go 11.4+
86+
- '^G102:' # gosec: we have to bind to all ifaces
87+
- '^G402:' # gosec: some services terminate at the load balancer
88+
- '^G505:' # gosec: we use crypto/sha1 for some HMACs
89+
- '^Range statement' # paralleltest: false positives
90+
91+
# default: 50
92+
max-issues-per-linter: 0
93+
94+
# default: 3
95+
max-same-issues: 0
96+
97+
severity:
98+
# default: ''
99+
default-severity: error

‎Makefile

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
IMAGE = "mock:latest"
2+
3+
# h - help
4+
h help:
5+
@echo "h help - this help"
6+
@echo "docker - run docker image build"
7+
.PHONY: h
8+
9+
10+
# docker build
11+
docker:
12+
docker build -f ./build/Dockerfile -t $(IMAGE) .
13+
.PHONY: docker

‎README.md

Copy file name to clipboardExpand all lines: README.md
+13-11Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ However, please **DO MAKE SURE TO TAKE A BACKUP** of your database before you mo
2222

2323
Check on the "Known Issues" section below for more information about current identified bugs.
2424

25-
# Table of Contents
25+
## Table of Contents
26+
2627
* [Important information and disclaimer](#important-information-and-disclaimer)
2728
* [Supported database engines &amp; data types](#supported-database-engines--data-types)
2829
* [Database Engine](#database-engine)
@@ -36,11 +37,11 @@ Check on the "Known Issues" section below for more information about current ide
3637
* [License](#license)
3738
* [Authors](#authors)
3839

39-
# Important information and disclaimer
40+
## Important information and disclaimer
4041

4142
Mock-data idea is to generate fake data in new test cluster and it is **NOT TO BE USED IN PRODUCTION ENVIRONMENTS**. Please ensure you have a backup of your database before running Mock-data in an environment you can't afford losing.
4243

43-
# Supported database engines & data types
44+
## Supported database engines & data types
4445

4546
### Database Engine
4647
+ PostgresSQL
@@ -51,7 +52,7 @@ Mock-data idea is to generate fake data in new test cluster and it is **NOT TO B
5152
+ All datatypes that are listed on the [postgres datatype](https://www.postgresql.org/docs/9.6/static/datatype.html) website are supported
5253
+ As Greenplum are both base from postgres, the supported postgres datatype also apply in their case
5354

54-
# How it works
55+
## How it works
5556

5657
+ PARSES the CLI arguments
5758
+ CHECKS if the database connection can be established
@@ -66,7 +67,8 @@ Mock-data idea is to generate fake data in new test cluster and it is **NOT TO B
6667
+ CHECK constraints are ignored (coming soon?)
6768
+ LOADS constraints that it had backed up (Mock-data can fail at this stage if its not able to fix the constraint violations)
6869

69-
# Usage
70+
## Usage
71+
7072
```
7173
$ mock --help
7274
This program generates fake data into a postgres database cluster.
@@ -100,7 +102,7 @@ Flags:
100102
Use "mock [command] --help" for more information about a command.
101103
```
102104

103-
# Installation
105+
## Installation
104106

105107
[Download](https://github.com/pivotal/mock-data/releases/latest) the latest release for your OS & Architecture and you're ready to go!
106108

@@ -114,7 +116,7 @@ chmod +x /usr/local/bin/mock
114116

115117
provided `/usr/local/bin` is part of the $PATH environment variable.
116118

117-
# Examples
119+
## Examples
118120

119121
Here is a simple demo of how the tool works, provide us your table and we will load the data for you
120122

@@ -129,15 +131,15 @@ For more examples how to use the tool, please check out the [wiki](https://githu
129131
* Read this section on how the subcommand [tables](https://github.com/pivotal-legacy/mock-data/wiki/Sub-command:-Tables) works
130132

131133

132-
# Known Issues
134+
## Known Issues
133135

134136
1. We do struggle when recreating constraints, even though we do try to fix the primary key , foreign key, unique key. So there is no guarantee that the tool will fix all the constraints and manual intervention is needed in some cases.
135137
2. If you have a composite unique index where one column is part of foreign key column then there are chances the constraint creation would fail.
136138
3. Fixing CHECK constraints isn't supported due to complexity, so recreating check constraints would fail, use `custom` subcommand to control the data being inserted
137139
4. On Greenplum Database partition tables are not supported (due to check constraint issues defined above), so use the `custom` sub command to define the data to be inserted to the column with check constraints
138140
5. Custom data types are not supported, use `custom` sub command to control the data for that custom data types
139141

140-
# Developers / Collaboration
142+
## Developers / Collaboration
141143

142144
You can sumbit issues or pull request via [github](https://github.com/pivotal/mock-data) and we will try our best to fix them.
143145

@@ -170,10 +172,10 @@ To customize this repository, follow the steps
170172
/bin/sh build.sh
171173
```
172174
173-
# License
175+
## License
174176
175177
The Project is licensed under [MIT](https://github.com/pivotal-legacy/mock-data/blob/master/LICENSE)
176178
177-
# Authors
179+
## Authors
178180
179181
[![Ignacio](https://img.shields.io/badge/github-Ignacio_Elizaga-green.svg?style=social)](https://github.com/ielizaga) [![Aitor](https://img.shields.io/badge/github-Aitor_Cedres-green.svg?style=social)](https://github.com/Zerpet) [![Juan](https://img.shields.io/badge/github-Juan_Ramos-green.svg?style=social)](https://github.com/jujoramos) [![Faisal](https://img.shields.io/badge/github-Faisal_Ali-green.svg?style=social)](https://github.com/faisaltheparttimecoder) [![Adam](https://img.shields.io/badge/github-Adam_Clevy-green.svg?style=social)](https://github.com/adamclevy)

‎build/Dockerfile

Copy file name to clipboard
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
############################
2+
# STEP 0 get dependencies
3+
############################
4+
FROM golang:1.16.5 AS dependencies
5+
WORKDIR /go/src
6+
COPY go.mod .
7+
COPY go.sum .
8+
RUN go mod download
9+
############################
10+
# STEP 1 build executable binary
11+
############################
12+
FROM dependencies AS builder
13+
##
14+
ENV GO111MODULE=on \
15+
CGO_ENABLED=0 \
16+
GOOS=linux \
17+
GOARCH=amd64
18+
19+
WORKDIR /go/src
20+
COPY . .
21+
##
22+
RUN go build -o /bin/mock .
23+
############################
24+
# STEP 2 build a small image
25+
############################
26+
FROM alpine:3.12
27+
28+
RUN addgroup -S mock; \
29+
adduser -S mock -G mock -D -u 10000 -h /home/mock -s /bin/nologin; \
30+
chown -R mock:mock /home/mock
31+
COPY --from=builder /bin/mock /usr/bin/mock
32+
VOLUME [ "/home/mock" ]
33+
34+
USER 10000
35+
36+
ENTRYPOINT [ "mock" ]
37+
CMD ["--help"]

‎cmd.go

Copy file name to clipboardExpand all lines: cmd.go
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
56
"github.com/spf13/cobra"
67
"github.com/spf13/viper"
78
)
@@ -125,7 +126,7 @@ var tablesCmd = &cobra.Command{
125126
}
126127
// either create fake tables or insert mock table rows are allowed, not together
127128
if cmdOptions.Tab.FakeNewTables && !IsStringEmpty(cmdOptions.Tab.FakeTablesRows) {
128-
Fatalf("Cannot perform create table & mock tables together, choose one", programName)
129+
Fatal("Cannot perform create table & mock tables together, choose one")
129130
}
130131
// if there is request for new tables and no of tables parameter is below 1 then error out
131132
if cmdOptions.Tab.FakeNewTables && cmdOptions.Tab.TotalTables < 1 {
@@ -194,7 +195,7 @@ var customCmd = &cobra.Command{
194195
}
195196
// If both is set
196197
if !IsStringEmpty(cmdOptions.Tab.FakeTablesRows) && !IsStringEmpty(cmdOptions.File) {
197-
Fatalf("Cannot run the table and loading of data via file together, choose one", programName)
198+
Fatalf("Cannot run the table and loading of data via file together, choose one")
198199
}
199200
},
200201
Run: func(cmd *cobra.Command, args []string) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.