-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from SohamRatnaparkhi/feature/db-refractor-and-…
…docker [upgrade][db-and-container] Version upgrade with db folder shift and dockerization
- Loading branch information
Showing
92 changed files
with
3,143 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
.PHONY: docker-build-all | ||
docker-build-all: | ||
docker build -t api-auth:v1 ./authentication | ||
|
||
.PHONY: docker-run-all | ||
docker-run-all: | ||
docker run -d \ | ||
--name db \ | ||
--network my-network \ | ||
-e POSTGRES_PASSWORD=foobarbaz \ | ||
-v pgdata:/var/lib/postgresql/data \ | ||
-p 5432:5432 \ | ||
--restart unless-stopped \ | ||
postgres:15.1-alpine | ||
|
||
docker run -d \ | ||
--name auth \ | ||
--network my-network \ | ||
-e POSTGRES_PASSWORD=foobarbaz \ | ||
-e DB_HOST=db \ | ||
-e DB_PORT=5432 \ | ||
-e DB_USER=postgres \ | ||
-e DB_PASSWORD=foobarbaz \ | ||
-e DB_NAME=blogx \ | ||
-e PORT=8080 \ | ||
-e JWT_SECRET_KEY=foobarbaz \ | ||
-e BCRYPT_SALT_VALUE=12 \ | ||
-e DB_URL="postgres://postgres:foobarbaz@db:5432/blogx?sslmode=disable" \ | ||
-p 8080:8080 \ | ||
--restart unless-stopped \ | ||
--link db \ | ||
api-auth:v1 | ||
|
||
docker run -d \ | ||
--name blog \ | ||
--network my-network \ | ||
-e POSTGRES_PASSWORD=foobarbaz \ | ||
-e DB_HOST=db \ | ||
-e DB_PORT=5432 \ | ||
-e DB_USER=postgres \ | ||
-e DB_PASSWORD=foobarbaz \ | ||
-e DB_NAME=blogx \ | ||
-e PORT=8081 \ | ||
-e JWT_SECRET_KEY=foobarbaz \ | ||
-e BCRYPT_SALT_VALUE=12 \ | ||
-e DB_URL="postgres://postgres:foobarbaz@db:5432/blogx?sslmode=disable" \ | ||
-p 8081:8081 \ | ||
--restart unless-stopped \ | ||
--link db \ | ||
api-blog:v1 | ||
|
||
.PHONY: docker-stop-all | ||
docker-stop-all: | ||
docker stop db | ||
docker stop auth | ||
docker stop blog | ||
|
||
.PHONY: docker-rm-all | ||
docker-rm-all: | ||
docker rm auth | ||
docker rm db | ||
docker rm blog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
FROM golang:1.20-bullseye AS build-base | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
|
||
RUN --mount=type=cache,target=/go/pkg/mod \ | ||
--mount=type=cache,target=/root/.cache/go-build \ | ||
go mod download | ||
|
||
###################### | ||
FROM build-base AS dev | ||
|
||
RUN go install github.com/mitranim/gow@latest | ||
|
||
# ENV PORT=8080 | ||
# ENV BCRYPT_SALT_VALUE=12 | ||
# ENV JWT_SECRET_KEY="blogx_secret_key" | ||
# ENV DB_URL="postgres://postgres:Soham@123*@localhost:5432/blogx_service_go" | ||
|
||
COPY . . | ||
|
||
CMD [ "gow", "run", "." ] | ||
|
||
###################### | ||
FROM build-base AS build-production | ||
|
||
# Add non root user | ||
RUN useradd -u 1001 nonroot | ||
|
||
COPY . . | ||
|
||
ENV PORT=8080 | ||
ENV BCRYPT_SALT_VALUE=12 | ||
ENV JWT_SECRET_KEY="blogx_secret_key" | ||
# ENV DB_URL="postgres://postgres:Soham@123*@localhost:5432/blogx_service_go" | ||
|
||
RUN go build \ | ||
-ldflags="-linkmode external -extldflags -static" \ | ||
-tags netgo \ | ||
-o main | ||
|
||
|
||
|
||
FROM scratch | ||
|
||
EXPOSE 8080 | ||
EXPOSE 5432 | ||
|
||
WORKDIR / | ||
# Copy the passwd file | ||
COPY --from=build-production /etc/passwd /etc/passwd | ||
|
||
# Copy the app binary from the build stage | ||
COPY --from=build-production /app/main main | ||
|
||
# Copy .env file | ||
COPY --from=build-production /app/.env .env | ||
|
||
# Use nonroot user | ||
USER nonroot | ||
|
||
|
||
CMD ["./main"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- name: CreateUser :one | ||
|
||
INSERT INTO | ||
users ( | ||
id, | ||
first_name, | ||
last_name, | ||
password, | ||
email, | ||
bio | ||
) | ||
VALUES ($1, $2, $3, $4, $5, $6) RETURNING *; | ||
|
||
-- name: GetUserByEmail :one | ||
|
||
SELECT * FROM users WHERE email = $1; | ||
|
||
-- name: DeleteUser :exec | ||
|
||
DELETE FROM users WHERE id = $1; |
Oops, something went wrong.