From 9d3d419edec72fcef7e284b87f2ee8c9882c26db Mon Sep 17 00:00:00 2001 From: Kshitij Gang Date: Wed, 4 Jan 2023 17:03:25 +0530 Subject: [PATCH 01/15] fix(first): basic --- Taskfile.yml | 3 +++ go.mod | 16 ++++++++-------- go.sum | 48 +++++++++++++++++++++++++----------------------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index a9152e7..3020850 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,6 +1,9 @@ version: '2' tasks: + hello: + cmds: + - echo "hello world" test: cmds: - echo " *** Running Coverage Tests ***" diff --git a/go.mod b/go.mod index 8e84815..39e6f32 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module go-template go 1.18 require ( - github.com/99designs/gqlgen v0.17.13 + github.com/99designs/gqlgen v0.17.22 github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/agiledragon/gomonkey/v2 v2.2.0 github.com/dgrijalva/jwt-go v3.2.0+incompatible @@ -24,11 +24,11 @@ require ( github.com/rafaeljusto/redigomock v2.4.0+incompatible github.com/rafaeljusto/redigomock/v3 v3.0.1 github.com/rs/zerolog v1.18.0 - github.com/rubenv/sql-migrate v1.1.2 + github.com/rubenv/sql-migrate v1.2.0 github.com/spf13/viper v1.12.0 github.com/stretchr/testify v1.8.0 github.com/uptrace/opentelemetry-go-extra/otelsql v0.1.14 - github.com/vektah/gqlparser/v2 v2.4.6 + github.com/vektah/gqlparser/v2 v2.5.1 github.com/volatiletech/null/v8 v8.1.2 github.com/volatiletech/randomize v0.0.1 github.com/volatiletech/sqlboiler v3.7.1+incompatible @@ -71,8 +71,8 @@ require ( github.com/inconshreveable/mousetrap v1.0.1 // indirect github.com/leodido/go-urn v1.2.1 // indirect github.com/magiconair/properties v1.8.6 // indirect - github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect @@ -99,11 +99,11 @@ require ( go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.8.0 // indirect golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect - golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect + golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect - golang.org/x/text v0.3.7 // indirect + golang.org/x/text v0.3.8 // indirect golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect - golang.org/x/tools v0.1.11 // indirect + golang.org/x/tools v0.1.12 // indirect golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect google.golang.org/protobuf v1.28.0 // indirect diff --git a/go.sum b/go.sum index bc17619..a4d362c 100644 --- a/go.sum +++ b/go.sum @@ -46,22 +46,20 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/99designs/gqlgen v0.17.13 h1:ETUEqvRg5Zvr1lXtpoRdj026fzVay0ZlJPwI33qXLIw= -github.com/99designs/gqlgen v0.17.13/go.mod h1:w1brbeOdqVyNJI553BGwtwdVcYu1LKeYE1opLWN9RgQ= +github.com/99designs/gqlgen v0.17.22 h1:TOcrF8t0T3I0za9JD3CB6ehq7dDEMjR9Onikf8Lc/04= +github.com/99designs/gqlgen v0.17.22/go.mod h1:BMhYIhe4bp7OlCo5I2PnowSK/Wimpv/YlxfNkqZGwLo= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.4.1/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= -github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= +github.com/Masterminds/sprig/v3 v3.2.0/go.mod h1:tWhwTbUTndesPNeF0C900vKoq283u6zp4APT9vaF3SI= github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8= github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -356,26 +354,27 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-oci8 v0.1.1/go.mod h1:wjDx6Xm9q7dFtHJvIlrI99JytznLw5wQ4R+9mNXJwGI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= -github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= -github.com/mattn/go-sqlite3 v1.14.10 h1:MLn+5bFRlWMGoSRmJour3CL1w/qL96mvipqpwQW/Sfk= github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= +github.com/mattn/go-sqlite3 v1.14.14 h1:qZgc/Rwetq+MtyE18WhzjokPD93dNqLGNT3QJuLvBGw= +github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= -github.com/mitchellh/cli v1.1.2/go.mod h1:6iaV0fGdElS6dPBx0EApTxHrcWvmJphyh2n8YBLPPZ4= +github.com/mitchellh/cli v1.1.4/go.mod h1:vTLESy5mRhKOs9KDp0/RATawxP1UqBmdrpVRMnpcvKQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= @@ -386,7 +385,6 @@ github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS4 github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.3.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.4.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -433,8 +431,8 @@ github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6po github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.18.0 h1:CbAm3kP2Tptby1i9sYy2MGRg0uxIN9cyDb59Ys7W8z8= github.com/rs/zerolog v1.18.0/go.mod h1:9nvC1axdVrAHcu/s9taAVfBuIdTZLVQmKQyvrUjF5+I= -github.com/rubenv/sql-migrate v1.1.2 h1:9M6oj4e//owVVHYrFISmY9LBRw6gzkCNmD9MV36tZeQ= -github.com/rubenv/sql-migrate v1.1.2/go.mod h1:/7TZymwxN8VWumcIxw1jjHEcR1djpdkMHQPT4FWdnbQ= +github.com/rubenv/sql-migrate v1.2.0 h1:fOXMPLMd41sK7Tg75SXDec15k3zg5WNV6SjuDRiNfcU= +github.com/rubenv/sql-migrate v1.2.0/go.mod h1:Z5uVnq7vrIrPmHbVFfR4YLHRZquxeHpckCnRq0P/K9Y= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -494,8 +492,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -github.com/vektah/gqlparser/v2 v2.4.6 h1:Yjzp66g6oVq93Jihbi0qhGnf/6zIWjcm8H6gA27zstE= -github.com/vektah/gqlparser/v2 v2.4.6/go.mod h1:flJWIR04IMQPGz+BXLrORkrARBxv/rtyIAFvd/MceW0= +github.com/vektah/gqlparser/v2 v2.5.1 h1:ZGu+bquAY23jsxDRcYpWjttRZrUz07LbiY77gUOHcr4= +github.com/vektah/gqlparser/v2 v2.5.1/go.mod h1:mPgqFBu/woKTVYWyNk8cO3kh4S/f4aRFZrvOnp3hmCs= github.com/volatiletech/inflect v0.0.1 h1:2a6FcMQyhmPZcLa+uet3VJ8gLn/9svWhJxJYwvE8KsU= github.com/volatiletech/inflect v0.0.1/go.mod h1:IBti31tG6phkHitLlr5j7shC5SOo//x0AjDzaJU1PLA= github.com/volatiletech/null/v8 v8.1.2 h1:kiTiX1PpwvuugKwfvUNX/SU/5A2KGZMXfGD0DUHdKEI= @@ -518,6 +516,7 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs= github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= @@ -616,7 +615,6 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -661,8 +659,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 h1:NWy5+hlRbC7HK+PmcXVUmW1IMyFce7to56IUvhUFm7Y= -golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -691,6 +689,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -757,6 +756,9 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 h1:Sx/u41w+OwrInGdEckYmEuU5gHoGSL4QbDz3S9s6j4U= golang.org/x/sys v0.0.0-20220818161305-2296e01440c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -770,8 +772,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -837,10 +840,9 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= -golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= -golang.org/x/tools v0.1.11 h1:loJ25fNOEhSXfHrpoGj91eCUThwdNX6u24rO1xnNteY= -golang.org/x/tools v0.1.11/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4= +golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From a641b759a6c01364e33cc8d6ae1aec2096034365 Mon Sep 17 00:00:00 2001 From: Kshitij Gang Date: Fri, 20 Jan 2023 09:47:04 +0530 Subject: [PATCH 02/15] feat: added changes to seeder and ecs setup --- .github/workflows/go-template-ci.yml | 10 +------ Dockerfile | 43 ++++++++++++++++---------- README.MD | 38 +++++++++++++++++++++-- cmd/seeder/exec/seed.go | 45 ++++++++++++++++++++++++++++ cmd/seeder/main.go | 13 ++++++-- cmd/seeder/utls/utls.go | 11 +++++-- internal/config/env.go | 8 +++-- scripts/migrate-and-run.sh | 6 ++-- scripts/setup-ecs.sh | 8 ++++- scripts/setup-local.sh | 9 ++++-- sonar-project.properties | 12 -------- 11 files changed, 148 insertions(+), 55 deletions(-) create mode 100644 cmd/seeder/exec/seed.go delete mode 100644 sonar-project.properties diff --git a/.github/workflows/go-template-ci.yml b/.github/workflows/go-template-ci.yml index 6d0809e..bbee473 100644 --- a/.github/workflows/go-template-ci.yml +++ b/.github/workflows/go-template-ci.yml @@ -40,15 +40,7 @@ jobs: fail_ci_if_error: true files: ./coverage.out verbose: true - - name: SonarCloud Scan - uses: sonarsource/sonarcloud-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - with: - args: > - -Dsonar.organization=${{ secrets.SONAR_ORG}} - -Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY}} + golangci-lint: runs-on: ubuntu-latest steps: diff --git a/Dockerfile b/Dockerfile index 38b8483..b9807f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,41 @@ -FROM golang:1.18-alpine3.16 -RUN apk add build-base +FROM golang:1.19 as builder -RUN mkdir -p /go/src/github.com/wednesday-solutions/go-template-mysql -ADD . /go/src/github.com/wednesday-solutions/go-template-mysql - -WORKDIR /go/src/github.com/wednesday-solutions/go-template-mysql +RUN mkdir /app +ADD . /app +WORKDIR /app +ENV ENVIRONMENT_NAME=docker RUN GOARCH=amd64 \ GOOS=linux \ CGO_ENABLED=0 \ go mod vendor -RUN mkdir -p /go/src/github.com/wednesday-solutions/go-template-mysql/output -RUN go build -o ./output/main ./cmd/server/main.go -RUN go build -o ./output/seeder ./cmd/seeder/main.go + +RUN go run ./cmd/seeder/main.go +RUN go build -o ./output/server ./cmd/server/main.go RUN go build -o ./output/migrations ./cmd/migrations/main.go +RUN go build -o ./output/seeder ./cmd/seeder/output/seed.go -FROM golang:1.18-alpine3.16 -ARG ENVIRONMENT_NAME -RUN mkdir -p /app/ -ADD . /app +FROM alpine:latest +ENV ENVIRONMENT_NAME=docker +RUN apk add --no-cache libc6-compat +RUN apk add --no-cache --upgrade bash +RUN mkdir -p /app/ WORKDIR /app -COPY --from=0 /go/src/github.com/wednesday-solutions/go-template-mysql/output /app/ +COPY /scripts /app/scripts/ +COPY --from=builder /app/output/ /app/output +COPY --from=builder /app/cmd/seeder/exec/build/ /app/output/cmd/seeder/exec/build/ +COPY ./.env.docker /app/output/ +COPY ./.env.docker /app/output/cmd/seeder/output/build/ +COPY ./.env.docker /app/output/cmd/seeder/output/ +COPY ./.env.docker /app/output/cmd/seeder/ +COPY ./.env.docker /app/output/cmd/ +COPY ./.env.docker /app/ +COPY ./scripts/ /app/ +COPY --from=builder /app/internal/migrations/ /app/internal/migrations/ +CMD ["bash","./migrate-and-run.sh"] +EXPOSE 9000 -CMD ["sh", "/app/scripts/migrate-and-run.sh"] -EXPOSE 9000 \ No newline at end of file diff --git a/README.MD b/README.MD index 41b6ae1..58f5d5e 100644 --- a/README.MD +++ b/README.MD @@ -229,12 +229,39 @@ gqlgen generate ### Create infrastructure +### Precautions +1. Please ensure the maximum limit of number of vpc's in a region has not reached it's limit. +2. The maximum limit of number of buckets has not reached it's limits. +3. Please make the changes to the manifest file of the service. +4. Ensure that the aws cli has been installed and configured with the appropriate credentials and profiles. + + + Application name should container only lowercase letters. No hyphens and underscores or any other special characters. + + ``` -./scripts/setup-ecs.sh gotemplatemysql dev +./scripts/setup-ecs.sh gotemplate dev +``` + + + +Also add the environment variables to the task,add this block of yml code in ${service name}/manifest.yaml: ``` +variables: + ENVIRONMENT_NAME: develop + + #to inject our .env file from aws s3 inside the container + +taskdef_overrides: + - path: ContainerDefinitions[0].EnvironmentFiles[0] + value: + type: 's3' + value: 'arn:aws:s3:::gotemplate-dev-bucket/develop/.env' + +``` Make sure that the manifest.yml has http.path: '/' ``` @@ -246,13 +273,18 @@ http: # healthcheck: '/' ``` +### To deploy + +``` +./scripts/deploy-ecs.sh gotemplate dev +``` + ### Update infrastructure ``` -./scripts/update-ecs.sh gotemplatemysql dev +./scripts/update-ecs.sh gotemplate dev ``` - ## Testing Get test coverage using diff --git a/cmd/seeder/exec/seed.go b/cmd/seeder/exec/seed.go new file mode 100644 index 0000000..5597b6c --- /dev/null +++ b/cmd/seeder/exec/seed.go @@ -0,0 +1,45 @@ +package main + +import ( + "bytes" + "fmt" + "log" + "os" + "os/exec" + + "golang.org/x/exp/slices" +) + +func main() { + + base, _ := os.Getwd() + log.Println(base) + + base += "/cmd/seeder/exec/build" + fmt.Println(base) + + files, err := os.ReadDir(base) + if err != nil { + log.Fatal(err) + } + log.Println(len(files)) + + for _, file := range files { + + log.Println(file.Name()) + if slices.Contains([]string{"seed.go", ".env.docker"}, file.Name()) { + continue + } + cmd := exec. + Command(fmt.Sprintf("%s/%s", base, file.Name())) + var outb, errb bytes.Buffer + cmd.Stdout = &outb + cmd.Stderr = &errb + err := cmd.Run() + if err != nil { + log.Fatal(err) + } + fmt.Println("out:", outb.String(), "err:", errb.String()) + + } +} diff --git a/cmd/seeder/main.go b/cmd/seeder/main.go index 4cc3841..43c00e5 100644 --- a/cmd/seeder/main.go +++ b/cmd/seeder/main.go @@ -7,10 +7,16 @@ import ( "log" "os" "os/exec" + "strings" "golang.org/x/exp/slices" ) +func stripFileExtension(fileName string) string { + s := strings.TrimRight(fileName, ".go") + return s +} + func main() { err := config.LoadEnv() if err != nil { @@ -26,18 +32,21 @@ func main() { } for _, file := range files { - if slices.Contains([]string{"main.go", "utls"}, file.Name()) { + if slices.Contains([]string{"main.go", "seed", "output", "exec", "build", "utls"}, file.Name()) { continue } filepath := base + "/" + file.Name() + // outputPath := base + "/output" files, err := os.ReadDir(filepath) if err != nil { log.Fatal(err) } for _, file := range files { fmt.Println(filepath + "/" + file.Name()) - cmd := exec.Command("go", "run", filepath+"/"+file.Name()) + cmd := exec. + Command("go", "build", "-o", + fmt.Sprintf("./cmd/seeder/exec/build/%s", stripFileExtension(file.Name())), filepath+"/"+file.Name()) data, err := cmd.CombinedOutput() if err != nil { zaplog.Logger.Error(string(data), err) diff --git a/cmd/seeder/utls/utls.go b/cmd/seeder/utls/utls.go index 9307e93..2989cd8 100644 --- a/cmd/seeder/utls/utls.go +++ b/cmd/seeder/utls/utls.go @@ -2,7 +2,8 @@ package utls import ( "fmt" - "go-template/internal/mysql" + "go-template/internal/config" + "go-template/internal/postgres" "go-template/pkg/utl/zaplog" "log" "strings" @@ -10,7 +11,11 @@ import ( // SeedData ... func SeedData(tableName string, rawQuery string) error { - db, err := mysql.Connect() + err := config.LoadEnv() + if err != nil { + fmt.Print(err) + } + db, err := postgres.Connect() if err != nil { zaplog.Logger.Error("error while connecting to seed data", err) @@ -23,7 +28,7 @@ func SeedData(tableName string, rawQuery string) error { for _, v := range queries[0 : len(queries)-1] { _, err := db.Exec(v) if err != nil { - zaplog.Logger.Error("error while executing seed script for ", tableName, err) + zaplog.Logger.Error("error while executing seed script for", tableName, err) log.Fatal(err) return err diff --git a/internal/config/env.go b/internal/config/env.go index 4b539de..3f2ea67 100644 --- a/internal/config/env.go +++ b/internal/config/env.go @@ -61,9 +61,11 @@ func LoadEnv() error { env = "local" } - err := godotenv.Load(fmt.Sprintf(".env.%s", env)) - if err != nil { - return err + if env != "develop" { + err := godotenv.Load(fmt.Sprintf(".env.%s", env)) + if err != nil { + return err + } } if env != "local" && env != "docker" { type copilotSecrets struct { diff --git a/scripts/migrate-and-run.sh b/scripts/migrate-and-run.sh index 805d76d..f64230b 100755 --- a/scripts/migrate-and-run.sh +++ b/scripts/migrate-and-run.sh @@ -2,11 +2,11 @@ echo $ENVIRONMENT_NAME -./migrations +./output/migrations if [[ $ENVIRONMENT_NAME == "docker" ]]; then echo "seeding" - ./seeder + ./output/seeder fi -./main \ No newline at end of file +./output/server \ No newline at end of file diff --git a/scripts/setup-ecs.sh b/scripts/setup-ecs.sh index f9c7dae..9042ccf 100755 --- a/scripts/setup-ecs.sh +++ b/scripts/setup-ecs.sh @@ -4,6 +4,12 @@ copilot init -a "$1" -t "Load Balanced Web Service" -n "$1-$2-svc" -d ./Dockerfi copilot env init --name $2 --profile default --default-config -copilot storage init -n "$1-$2-cluster" -t Aurora -w "$1-$2-svc" --engine MySQL --initial-db "$1_$2_db" +copilot env deploy --name $2 + +copilot storage init -n "$1-$2-cluster" -t Aurora -w "$1-$2-svc" --engine PostgreSQL --initial-db "$1_$2_db" + +copilot storage init -n "$1-$2-bucket" -t S3 + +aws s3 cp .env "s3://$1-$2-bucket/develop/" # copilot deploy --name "$1-$2-svc" -e "$2" diff --git a/scripts/setup-local.sh b/scripts/setup-local.sh index b982c19..b719192 100755 --- a/scripts/setup-local.sh +++ b/scripts/setup-local.sh @@ -1,10 +1,13 @@ #!/bin/sh set -a && source .env.local && set +a -export MYSQL_HOST=localhost -# drop first and then run migrations - +export PSQL_HOST=localhost +# drop first go run ./cmd/migrations/main.go down +# run migrations +go run ./cmd/migrations/main.go + # seed data go run ./cmd/seeder/main.go +go run ./cmd/seeder/exec/seed.go \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index 15a40e2..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1,12 +0,0 @@ -sonar.projectKey=gotemplatemysql -sonar.projectName=Go Template Mysql -sonar.sources=. -sonar.test.inclusions=**/*_test.go -sonar.test.exclusions=**/vendor/**,**/testutls/**/*.go,**/gqlmodels/**/*.go,**/cmd/**/*.go, -sonar.coverage.exclusions=**/vendor/**,**/testutls/**/*.go,**/gqlmodels/**/*.go,**/cmd/**/*.go, -sonar.tests=. -sonar.language=go -sonar.sourceEncoding=UTF-8 -sonar.go.tests.reportPaths=report.json -sonar.go.coverage.reportPaths=coverage.out -sonar.exclusions=**/gqlmodels/**,**/models**,**/postman/**,**/copilot/**,**/testutls/**,**/cmd/** \ No newline at end of file From a84d719a5fc79402f6f704096d6738f579006ea3 Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 11:18:55 +0530 Subject: [PATCH 03/15] bug fixes --- cmd/seeder/utls/utls.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/seeder/utls/utls.go b/cmd/seeder/utls/utls.go index 2989cd8..04d4c7b 100644 --- a/cmd/seeder/utls/utls.go +++ b/cmd/seeder/utls/utls.go @@ -3,7 +3,7 @@ package utls import ( "fmt" "go-template/internal/config" - "go-template/internal/postgres" + "go-template/internal/mysql" "go-template/pkg/utl/zaplog" "log" "strings" @@ -15,7 +15,7 @@ func SeedData(tableName string, rawQuery string) error { if err != nil { fmt.Print(err) } - db, err := postgres.Connect() + db, err := mysql.Connect() if err != nil { zaplog.Logger.Error("error while connecting to seed data", err) From 7c575957f9c72bff2cde8953b350ed8e26ac597a Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 11:21:50 +0530 Subject: [PATCH 04/15] bug fixes --- .github/workflows/go-template-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go-template-ci.yml b/.github/workflows/go-template-ci.yml index bbee473..4ef4a1d 100644 --- a/.github/workflows/go-template-ci.yml +++ b/.github/workflows/go-template-ci.yml @@ -19,7 +19,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.19 - name: Install pre-commit dependencies run: | go install github.com/fzipp/gocyclo/cmd/gocyclo@latest From 1d4de98d82bad204e2fdd2689843f0779fadeaf3 Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 11:36:06 +0530 Subject: [PATCH 05/15] add changes related to env config from go template --- .env.base | 14 +++++++++++ .env.docker | 34 +++++++++----------------- .env.local | 33 +++++++++---------------- internal/config/env.go | 35 ++++++++++++++++++++------- internal/config/env_test.go | 48 +++++++++++++++++++++++++++---------- 5 files changed, 98 insertions(+), 66 deletions(-) create mode 100644 .env.base diff --git a/.env.base b/.env.base new file mode 100644 index 0000000..e48a012 --- /dev/null +++ b/.env.base @@ -0,0 +1,14 @@ +ENV_INJECTION=true +SERVER_DEBUG=true +SERVER_READ_TIMEOUT=10 +SERVER_WRITE_TIMEOUT=5 +JWT_MIN_SECRET_LENGTH=64 +JWT_DURATION_MINUTES=1440 +JWT_REFRESH_DURATION=3499200 +JWT_MAX_REFRESH=1440 +JWT_SIGNING_ALGORITHM=HS256 +DB_LOG_QUERIES=true +DB_TIMEOUT_SECONDS=5 +APP_MIN_PASSWORD_STR=1 +SERVER_PORT=9000 +COPILOT_DB_CREDS_VIA_SECRETS_MANAGER=false \ No newline at end of file diff --git a/.env.docker b/.env.docker index 9da787a..1e7df91 100644 --- a/.env.docker +++ b/.env.docker @@ -1,26 +1,14 @@ -APP_MIN_PASSWORD_STR=1 -DB_LOG_QUERIES=true -DB_TIMEOUT_SECONDS=5 ENVIRONMENT_NAME=docker -JWT_DURATION_MINUTES=1440 -JWT_MAX_REFRESH=1440 -JWT_MIN_SECRET_LENGTH=64 -JWT_REFRESH_DURATION=3499200 JWT_SECRET=aa60b52e-7974-11ea-bc55-0242ac130003b08d6654-7974-11ea-bc55-0242ac130003-b08d6654-7974-11ea-bc55-0242ac130003 -JWT_SIGNING_ALGORITHM=HS256 -MYSQL_DBNAME=go_template -MYSQL_DEBUG=true -MYSQL_HOST=db -MYSQL_PASS=password -MYSQL_PORT=3306 -MYSQL_ROOT_PASSWORD=password -MYSQL_SSLMODE=false -MYSQL_USER=def_user +PGADMIN_EMAIL=admin@w.is +PGADMIN_PASS=admin +PGADMIN_PORT=5000 +PSQL_DBNAME=go_template +PSQL_HOST=db +PSQL_PASS=go_template_role456 +PSQL_PORT=5432 +PSQL_SSLMODE=disable +PSQL_USER=go_template_role REDIS_ADDRESS=redis:6379 -SERVER_DEBUG=true -SERVER_PORT=9000 -SERVER_READ_TIMEOUT=10 -SERVER_WRITE_TIMEOUT=5 -SERVICE_NAME=goTemplateMySQL -INSECURE_MODE=true -OTEL_EXPORTER_OTLP_ENDPOINT=otel:4317 \ No newline at end of file +COPILOT_DB_CREDS_VIA_SECRETS_MANAGER=false +SERVER_PORT=9000 \ No newline at end of file diff --git a/.env.local b/.env.local index 0ce0790..674e161 100644 --- a/.env.local +++ b/.env.local @@ -1,27 +1,16 @@ -APP_MIN_PASSWORD_STR=1 -DB_LOG_QUERIES=true -DB_SSL=disable -DB_TIMEOUT_SECONDS=5 ENVIRONMENT_NAME=local -JWT_DURATION_MINUTES=1440 -JWT_MAX_REFRESH=1440 -JWT_MIN_SECRET_LENGTH=64 -JWT_REFRESH_DURATION=3499200 JWT_SECRET=aa60b52e-7974-11ea-bc55-0242ac130003b08d6654-7974-11ea-bc55-0242ac130003-b08d6654-7974-11ea-bc55-0242ac130003 -JWT_SIGNING_ALGORITHM=HS256 -MYSQL_DBNAME=go_template -MYSQL_DEBUG=true -MYSQL_HOST=localhost -MYSQL_PASS=password -MYSQL_PORT=3306 -MYSQL_ROOT_PASSWORD=password -MYSQL_SSLMODE=false -MYSQL_USER=root +PGADMIN_EMAIL=admin@w.is +PGADMIN_PASS=admin +PGADMIN_PORT=5000 +PSQL_DBNAME=go_template +PSQL_HOST=localhost +PSQL_PASS=go_template_role456 +PSQL_PORT=5432 +PSQL_SSLMODE=disable +PSQL_USER=go_template_role REDIS_ADDRESS=localhost:6379 -SERVER_DEBUG=true -SERVER_PORT=9000 -SERVER_READ_TIMEOUT=10 -SERVER_WRITE_TIMEOUT=5 -SERVICE_NAME=goTemplateMySQL +SERVICE_NAME=goTemplate INSECURE_MODE=true OTEL_EXPORTER_OTLP_ENDPOINT=localhost:4317 +COPILOT_DB_CREDS_VIA_SECRETS_MANAGER=false \ No newline at end of file diff --git a/internal/config/env.go b/internal/config/env.go index 3f2ea67..50a8d89 100644 --- a/internal/config/env.go +++ b/internal/config/env.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "go-template/pkg/utl/convert" + "log" "os" "strconv" @@ -53,21 +54,36 @@ func FileName() string { return envFileName } -func LoadEnv() error { - envName := "ENVIRONMENT_NAME" - env := os.Getenv(envName) +func LoadEnvWithFilePrefix(fileprefix *string) error { + prefix := "" + if fileprefix != nil { + prefix = *fileprefix + } + err := godotenv.Load(fmt.Sprintf("%s.env.base", prefix)) + if err != nil { + return err + } - if env == "" { - env = "local" + envName := os.Getenv("ENVIRONMENT_NAME") + if envName == "" { + envName = "local" } + log.Println("envName: " + envName) + + envVarInjection := GetBool("ENV_INJECTION") + if !envVarInjection || envName == "local" { + err = godotenv.Load(fmt.Sprintf("%s.env.%s", prefix, envName)) - if env != "develop" { - err := godotenv.Load(fmt.Sprintf(".env.%s", env)) if err != nil { + fmt.Printf(".env.%s\n", envName) + log.Println(err) return err } } - if env != "local" && env != "docker" { + + dbCredsInjected := GetBool("COPILOT_DB_CREDS_VIA_SECRETS_MANAGER") + + if dbCredsInjected { type copilotSecrets struct { Username string `json:"username"` Host string `json:"host"` @@ -92,3 +108,6 @@ func LoadEnv() error { return nil } +func LoadEnv() error { + return LoadEnvWithFilePrefix(nil) +} diff --git a/internal/config/env_test.go b/internal/config/env_test.go index 335f5ff..9cc6363 100644 --- a/internal/config/env_test.go +++ b/internal/config/env_test.go @@ -157,11 +157,11 @@ func TestLoadEnv(t *testing.T) { tapped bool dbSecret string } - username := "TEST" - host := "TEST" - dbname := "TEST" - password := "TEST" - port := "10" + username := "go_template_role" + host := "localhost" + dbname := "go_template" + password := "go_template_role456" + port := "5432" tests := []struct { name string wantErr bool @@ -178,25 +178,35 @@ func TestLoadEnv(t *testing.T) { args: args{env: "local", tapped: false}, }, { - name: "Fail to load develop env", + name: "Env varInjection Error", wantErr: true, - args: args{ - env: "develop", - tapped: false, - }, + args: args{env: "local", tapped: false}, }, + { + name: "dbCredsInjected True", + wantErr: true, + args: args{env: "", tapped: false}, + }, + { name: "Successfully load develop env", wantErr: false, args: args{ - env: "develop", + env: "production", tapped: false, dbSecret: fmt.Sprintf(`{"username":"%s",`+ `"host":"%s","dbname":"%s","password":"%s",`+ `"port":%s}`, username, host, dbname, password, port), }, }, - + { + name: "dbCredsInjected True", + wantErr: false, + args: args{env: "", tapped: false, dbSecret: fmt.Sprintf(`{"username":"%s",`+ + `"host":"%s","dbname":"%s","password":"%s",`+ + `"port":%s}`, username, host, dbname, password, port), + }, + }, { name: "Failed to load env", wantErr: true, @@ -208,22 +218,34 @@ func TestLoadEnv(t *testing.T) { }, } for _, tt := range tests { + ApplyFunc(godotenv.Load, func(filenames ...string) (err error) { // togglel whenever this file is loaded tt.args.tapped = true if tt.args.err == "" { + + if tt.name == "Env varInjection Error" && len(filenames) > 0 && filenames[0] == ".env.local" { + return fmt.Errorf(tt.args.err) + } + return nil } return fmt.Errorf(tt.args.err) }) os.Setenv("ENVIRONMENT_NAME", tt.args.env) - if tt.args.dbSecret != "" { os.Setenv("DB_SECRET", tt.args.dbSecret) } t.Run(tt.name, func(t *testing.T) { + if tt.name == "dbCredsInjected True" { + ApplyFunc(GetBool, func(key string) bool { + return true + }) + } + tapped := tt.args.tapped + if err := LoadEnv(); (err != nil) != tt.wantErr { t.Errorf("LoadEnv() error = %v, wantErr %v", err, tt.wantErr) } From fb5454ff8c010c314035e08d794cb8155429fe55 Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 12:09:05 +0530 Subject: [PATCH 06/15] made changes to resolver test according to new env file pattern --- .env.docker | 25 +++++++++++------- .env.local | 32 +++++++++++++++-------- internal/config/config_test.go | 3 ++- internal/mysql/mysql_test.go | 2 +- resolver/auth_mutations.resolvers_test.go | 12 ++++----- resolver/user_mutations.resolvers_test.go | 12 ++++----- testutls/main.go | 11 ++++++++ 7 files changed, 61 insertions(+), 36 deletions(-) diff --git a/.env.docker b/.env.docker index 1e7df91..d698c76 100644 --- a/.env.docker +++ b/.env.docker @@ -1,14 +1,19 @@ ENVIRONMENT_NAME=docker JWT_SECRET=aa60b52e-7974-11ea-bc55-0242ac130003b08d6654-7974-11ea-bc55-0242ac130003-b08d6654-7974-11ea-bc55-0242ac130003 -PGADMIN_EMAIL=admin@w.is -PGADMIN_PASS=admin -PGADMIN_PORT=5000 -PSQL_DBNAME=go_template -PSQL_HOST=db -PSQL_PASS=go_template_role456 -PSQL_PORT=5432 -PSQL_SSLMODE=disable -PSQL_USER=go_template_role + REDIS_ADDRESS=redis:6379 COPILOT_DB_CREDS_VIA_SECRETS_MANAGER=false -SERVER_PORT=9000 \ No newline at end of file +SERVER_PORT=9000 + + +MYSQL_DBNAME=go_template +MYSQL_DEBUG=true +MYSQL_HOST=db +MYSQL_PASS=password +MYSQL_PORT=3306 +MYSQL_ROOT_PASSWORD=password +MYSQL_SSLMODE=false +MYSQL_USER=def_user +REDIS_ADDRESS=redis:6379 +SERVER_DEBUG=true +SERVER_PORT=9000 diff --git a/.env.local b/.env.local index 674e161..174b697 100644 --- a/.env.local +++ b/.env.local @@ -1,16 +1,26 @@ ENVIRONMENT_NAME=local JWT_SECRET=aa60b52e-7974-11ea-bc55-0242ac130003b08d6654-7974-11ea-bc55-0242ac130003-b08d6654-7974-11ea-bc55-0242ac130003 -PGADMIN_EMAIL=admin@w.is -PGADMIN_PASS=admin -PGADMIN_PORT=5000 -PSQL_DBNAME=go_template -PSQL_HOST=localhost -PSQL_PASS=go_template_role456 -PSQL_PORT=5432 -PSQL_SSLMODE=disable -PSQL_USER=go_template_role REDIS_ADDRESS=localhost:6379 SERVICE_NAME=goTemplate INSECURE_MODE=true -OTEL_EXPORTER_OTLP_ENDPOINT=localhost:4317 -COPILOT_DB_CREDS_VIA_SECRETS_MANAGER=false \ No newline at end of file +OTEL_EXPORTER_OTLP_ENDPOINT=localhost:3306 +COPILOT_DB_CREDS_VIA_SECRETS_MANAGER=false + + + +MYSQL_DBNAME=go_template +MYSQL_DEBUG=true +MYSQL_HOST=localhost +MYSQL_PASS=password +MYSQL_PORT=3306 +MYSQL_ROOT_PASSWORD=password +MYSQL_SSLMODE=false +MYSQL_USER=root +REDIS_ADDRESS=localhost:6379 +SERVER_DEBUG=true +SERVER_PORT=9000 +SERVER_READ_TIMEOUT=10 +SERVER_WRITE_TIMEOUT=5 +SERVICE_NAME=goTemplateMySQL +INSECURE_MODE=true +OTEL_EXPORTER_OTLP_ENDPOINT=localhost:4317 \ No newline at end of file diff --git a/internal/config/config_test.go b/internal/config/config_test.go index ead5308..c5cd4af 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -6,6 +6,7 @@ import ( "testing" "go-template/internal/config" + "go-template/pkg/utl/convert" "go-template/testutls" . "github.com/agiledragon/gomonkey/v2" @@ -59,7 +60,7 @@ func TestLoad(t *testing.T) { for _, tt := range cases { t.Run(tt.name, func(t *testing.T) { - _, _, err := testutls.SetupEnvAndDB(t, testutls.Parameters{EnvFileLocation: "../../.env.local"}) + err := config.LoadEnvWithFilePrefix((convert.StringToPointerString("./../../"))) if err != nil { fmt.Print("error loading .env file") } diff --git a/internal/mysql/mysql_test.go b/internal/mysql/mysql_test.go index 3004827..6b2d426 100644 --- a/internal/mysql/mysql_test.go +++ b/internal/mysql/mysql_test.go @@ -27,7 +27,7 @@ func TestGetDSN(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - testutls.SetupEnv("../../.env.local") + testutls.SetupEnv("./../../.env.local") if got := mysql.GetDSN(); got != tt.want { t.Errorf("GetDSN() = %v, want %v", got, tt.want) } diff --git a/resolver/auth_mutations.resolvers_test.go b/resolver/auth_mutations.resolvers_test.go index 658dbb8..15eaad8 100644 --- a/resolver/auth_mutations.resolvers_test.go +++ b/resolver/auth_mutations.resolvers_test.go @@ -56,13 +56,11 @@ func TestLogin( t.Run( tt.name, func(t *testing.T) { - err := godotenv.Load("../.env.local") - if err != nil { - fmt.Print( - "error loading .env file", - ) - } - db, mock, err := sqlmock.New() + + mock, db, err := testutls.SetupEnvAndDB(t, testutls.Parameters{ + EnvFileLocation: "./../.env.local", + }) + godotenv.Load("./../.env.base") if err != nil { t.Fatalf( "an error '%s' was not expected when opening a stub database connection", diff --git a/resolver/user_mutations.resolvers_test.go b/resolver/user_mutations.resolvers_test.go index 56ede55..a37f61f 100644 --- a/resolver/user_mutations.resolvers_test.go +++ b/resolver/user_mutations.resolvers_test.go @@ -12,10 +12,10 @@ import ( "testing" . "github.com/agiledragon/gomonkey/v2" + "github.com/joho/godotenv" "golang.org/x/crypto/bcrypt" "github.com/DATA-DOG/go-sqlmock" - "github.com/joho/godotenv" "github.com/stretchr/testify/assert" "github.com/volatiletech/sqlboiler/v4/boil" ) @@ -237,11 +237,11 @@ func TestDeleteUser( t.Run( tt.name, func(t *testing.T) { - err := godotenv.Load("../.env.local") - if err != nil { - fmt.Print("error loading .env file") - } - db, mock, err := sqlmock.New() + + mock, db, err := testutls.SetupEnvAndDB(t, testutls.Parameters{ + EnvFileLocation: "./../.env.local", + }) + godotenv.Load("./../.env.base") if err != nil { t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) } diff --git a/testutls/main.go b/testutls/main.go index 469eee3..e8cb68b 100644 --- a/testutls/main.go +++ b/testutls/main.go @@ -111,6 +111,17 @@ func SetupEnvAndDB(t *testing.T, parameters Parameters) (mock sqlmock.Sqlmock, d return mock, db, nil } +func SetupMockDB(t *testing.T) (mock sqlmock.Sqlmock, db *sql.DB, err error) { + db, mock, err = sqlmock.New() + if err != nil { + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + } + boil.SetDB(db) + return mock, db, nil +} + type QueryData struct { Actions *[]driver.Value Query string From 8e8c4fbbf8b549ccef95bccb1f5638b252324b98 Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 12:11:39 +0530 Subject: [PATCH 07/15] made changes to resolver test according to new env file pattern --- resolver/auth_mutations.resolvers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolver/auth_mutations.resolvers_test.go b/resolver/auth_mutations.resolvers_test.go index 15eaad8..6106b54 100644 --- a/resolver/auth_mutations.resolvers_test.go +++ b/resolver/auth_mutations.resolvers_test.go @@ -60,7 +60,7 @@ func TestLogin( mock, db, err := testutls.SetupEnvAndDB(t, testutls.Parameters{ EnvFileLocation: "./../.env.local", }) - godotenv.Load("./../.env.base") + err = godotenv.Load("./../.env.base") if err != nil { t.Fatalf( "an error '%s' was not expected when opening a stub database connection", From 8f491eff41e2a7eee343b4baecdf114ffd9fab37 Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 12:12:12 +0530 Subject: [PATCH 08/15] made changes to resolver test according to new env file pattern --- resolver/auth_mutations.resolvers_test.go | 6 ++++++ resolver/user_mutations.resolvers_test.go | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/resolver/auth_mutations.resolvers_test.go b/resolver/auth_mutations.resolvers_test.go index 6106b54..bc96512 100644 --- a/resolver/auth_mutations.resolvers_test.go +++ b/resolver/auth_mutations.resolvers_test.go @@ -60,6 +60,12 @@ func TestLogin( mock, db, err := testutls.SetupEnvAndDB(t, testutls.Parameters{ EnvFileLocation: "./../.env.local", }) + if err != nil { + t.Fatalf( + "an error '%s' was not expected when opening a stub database connection", + err, + ) + } err = godotenv.Load("./../.env.base") if err != nil { t.Fatalf( diff --git a/resolver/user_mutations.resolvers_test.go b/resolver/user_mutations.resolvers_test.go index a37f61f..ea190bb 100644 --- a/resolver/user_mutations.resolvers_test.go +++ b/resolver/user_mutations.resolvers_test.go @@ -241,7 +241,13 @@ func TestDeleteUser( mock, db, err := testutls.SetupEnvAndDB(t, testutls.Parameters{ EnvFileLocation: "./../.env.local", }) - godotenv.Load("./../.env.base") + if err != nil { + t.Fatalf( + "an error '%s' was not expected when opening a stub database connection", + err, + ) + } + err = godotenv.Load("./../.env.base") if err != nil { t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) } From f607abd03f1d9e3c00786af7db7bf165b543631a Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 12:20:35 +0530 Subject: [PATCH 09/15] added sonar qube to github action --- .github/workflows/go-template-ci.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go-template-ci.yml b/.github/workflows/go-template-ci.yml index 4ef4a1d..fe4cbd4 100644 --- a/.github/workflows/go-template-ci.yml +++ b/.github/workflows/go-template-ci.yml @@ -34,12 +34,22 @@ jobs: run: go build ./... - name: Test run: ./scripts/test.sh - - uses: codecov/codecov-action@v2 + - name: SonarQube Scan + uses: sonarsource/sonarqube-scan-action@master with: - token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: true - files: ./coverage.out - verbose: true + args: > + -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + - uses: sonarsource/sonarqube-quality-gate-action@master + timeout-minutes: 5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} +# testing image url golangci-lint: runs-on: ubuntu-latest From 1bf6684aea4d8e2c519db87826fceb518cf5d451 Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 12:24:11 +0530 Subject: [PATCH 10/15] added sonar qube to github action --- sonar-project.properties | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 sonar-project.properties diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..15a40e2 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,12 @@ +sonar.projectKey=gotemplatemysql +sonar.projectName=Go Template Mysql +sonar.sources=. +sonar.test.inclusions=**/*_test.go +sonar.test.exclusions=**/vendor/**,**/testutls/**/*.go,**/gqlmodels/**/*.go,**/cmd/**/*.go, +sonar.coverage.exclusions=**/vendor/**,**/testutls/**/*.go,**/gqlmodels/**/*.go,**/cmd/**/*.go, +sonar.tests=. +sonar.language=go +sonar.sourceEncoding=UTF-8 +sonar.go.tests.reportPaths=report.json +sonar.go.coverage.reportPaths=coverage.out +sonar.exclusions=**/gqlmodels/**,**/models**,**/postman/**,**/copilot/**,**/testutls/**,**/cmd/** \ No newline at end of file From 912b0983a4fabb85f43119cf8f1c5474f9695068 Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 12:28:31 +0530 Subject: [PATCH 11/15] added sonar qube to github action --- scripts/setup-ecs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup-ecs.sh b/scripts/setup-ecs.sh index 9042ccf..2a1a3f0 100755 --- a/scripts/setup-ecs.sh +++ b/scripts/setup-ecs.sh @@ -10,6 +10,6 @@ copilot storage init -n "$1-$2-cluster" -t Aurora -w "$1-$2-svc" --engine Postgr copilot storage init -n "$1-$2-bucket" -t S3 -aws s3 cp .env "s3://$1-$2-bucket/develop/" +aws s3 cp .env "s3://$1-$2-bucket/$2/" # copilot deploy --name "$1-$2-svc" -e "$2" From ae4d9903eae0f29c96dfce86569fa288b8efac34 Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 13:11:38 +0530 Subject: [PATCH 12/15] added sonar qube to github action --- .github/workflows/go-template-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/go-template-ci.yml b/.github/workflows/go-template-ci.yml index fe4cbd4..f082db3 100644 --- a/.github/workflows/go-template-ci.yml +++ b/.github/workflows/go-template-ci.yml @@ -15,6 +15,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - uses: actions/setup-python@v3 - name: Install Go uses: actions/setup-go@v3 From fc86219648d4ee4fdccc154e8479b78c0b2f82af Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 14:13:30 +0530 Subject: [PATCH 13/15] added sonar qube to github action --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 15a40e2..cd9b01d 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,4 +1,4 @@ -sonar.projectKey=gotemplatemysql +sonar.projectKey=wednesday-solutions_go-template-mysql_AYbbZwibDgt5YEw3Xf7J sonar.projectName=Go Template Mysql sonar.sources=. sonar.test.inclusions=**/*_test.go From 4a6d08ce222737294fa87720a80b898a9642dca2 Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 14:48:06 +0530 Subject: [PATCH 14/15] bug fixes --- .env.base | 2 +- Dockerfile | 41 ++++++++++++++++++++++---------------- docker-compose.yml | 2 ++ scripts/migrate-and-run.sh | 6 +++--- scripts/setup-local.sh | 2 +- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/.env.base b/.env.base index e48a012..e4d720c 100644 --- a/.env.base +++ b/.env.base @@ -1,4 +1,4 @@ -ENV_INJECTION=true +ENV_INJECTION=false SERVER_DEBUG=true SERVER_READ_TIMEOUT=10 SERVER_WRITE_TIMEOUT=5 diff --git a/Dockerfile b/Dockerfile index b9807f7..a70d7f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,41 +1,48 @@ -FROM golang:1.19 as builder - +FROM golang:1.18-alpine3.16 as builder +RUN apk add build-base RUN mkdir /app ADD . /app WORKDIR /app -ENV ENVIRONMENT_NAME=docker +ARG ENVIRONMENT_NAME +ENV ENVIRONMENT_NAME=$ENVIRONMENT_NAME RUN GOARCH=amd64 \ GOOS=linux \ CGO_ENABLED=0 \ go mod vendor + RUN go run ./cmd/seeder/main.go RUN go build -o ./output/server ./cmd/server/main.go RUN go build -o ./output/migrations ./cmd/migrations/main.go -RUN go build -o ./output/seeder ./cmd/seeder/output/seed.go - +RUN go build -o ./output/seeder ./cmd/seeder/exec/seed.go FROM alpine:latest -ENV ENVIRONMENT_NAME=docker RUN apk add --no-cache libc6-compat RUN apk add --no-cache --upgrade bash +RUN addgroup -S nonroot \ + && adduser -S nonroot -G nonroot + + +ARG ENVIRONMENT_NAME +ENV ENVIRONMENT_NAME=$ENVIRONMENT_NAME + RUN mkdir -p /app/ WORKDIR /app +USER nonroot COPY /scripts /app/scripts/ -COPY --from=builder /app/output/ /app/output -COPY --from=builder /app/cmd/seeder/exec/build/ /app/output/cmd/seeder/exec/build/ -COPY ./.env.docker /app/output/ -COPY ./.env.docker /app/output/cmd/seeder/output/build/ -COPY ./.env.docker /app/output/cmd/seeder/output/ -COPY ./.env.docker /app/output/cmd/seeder/ -COPY ./.env.docker /app/output/cmd/ -COPY ./.env.docker /app/ +COPY --from=builder /app/output/ /app/ +COPY --from=builder /app/cmd/seeder/exec/build/ /app/cmd/seeder/exec/build/ + +COPY ./.env.* /app/output/ +COPY ./.env.* /app/output/cmd/seeder/exec/build/ +COPY ./.env.* /app/output/cmd/seeder/exec/ +COPY ./.env.* /app/output/cmd/seeder/ +COPY ./.env.* /app/output/cmd/ +COPY ./.env.* /app/ COPY ./scripts/ /app/ COPY --from=builder /app/internal/migrations/ /app/internal/migrations/ -CMD ["bash","./migrate-and-run.sh"] -EXPOSE 9000 - +CMD ["bash","./migrate-and-run.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 55de241..e1e2dc4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,5 +36,7 @@ services: condition: service_completed_successfully ports: - ${SERVER_PORT}:${SERVER_PORT} + environment: + ENVIRONMENT_NAME: ${ENVIRONMENT_NAME} \ No newline at end of file diff --git a/scripts/migrate-and-run.sh b/scripts/migrate-and-run.sh index f64230b..0b88495 100755 --- a/scripts/migrate-and-run.sh +++ b/scripts/migrate-and-run.sh @@ -2,11 +2,11 @@ echo $ENVIRONMENT_NAME -./output/migrations +./migrations if [[ $ENVIRONMENT_NAME == "docker" ]]; then echo "seeding" - ./output/seeder + ./seeder fi -./output/server \ No newline at end of file +./server \ No newline at end of file diff --git a/scripts/setup-local.sh b/scripts/setup-local.sh index b719192..e9c694b 100755 --- a/scripts/setup-local.sh +++ b/scripts/setup-local.sh @@ -1,7 +1,7 @@ #!/bin/sh set -a && source .env.local && set +a -export PSQL_HOST=localhost +export MYSQL_HOST=localhost # drop first go run ./cmd/migrations/main.go down From 237dc6c1a78a5737e0272dd155b1f7b6b635ba54 Mon Sep 17 00:00:00 2001 From: gang-wednesday Date: Mon, 17 Apr 2023 15:16:32 +0530 Subject: [PATCH 15/15] bug fixes --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a70d7f0..03e8615 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.18-alpine3.16 as builder +FROM golang:1.18-alpine3.16 AS builder RUN apk add build-base RUN mkdir /app