Add Dockerfile for backend (#60)
* Add Dockerfile for backend Fixes #57 * Add Dockerfile for backend Fixes #57 * removes a temporary test relict
This commit is contained in:
parent
796158b436
commit
a9c53952de
13
Makefile
13
Makefile
@ -1,14 +1,19 @@
|
||||
DB_URL=postgresql://root:secret@localhost:5432/df?sslmode=disable
|
||||
|
||||
reset_docker:
|
||||
docker rm -vf df; docker rmi -f df; docker rm -vf postgres; docker rmi -f postgres
|
||||
|
||||
initialize:
|
||||
go mod tidy && docker run --name postgres -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret -d postgres:15-alpine && sleep 5 && make network && make createdb && make migrateup && make test
|
||||
backend_build_image:
|
||||
docker build -t df:latest -f bff/Dockerfile
|
||||
|
||||
backend_run:
|
||||
make createdb; make migrateup; docker rm -vf df; docker run --name df --rmi -p 8080:8080 --network df-network -d df:latest
|
||||
|
||||
network:
|
||||
docker network create df-network
|
||||
|
||||
postgres:
|
||||
docker start postgres || docker run --name postgres -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret -d postgres:15-alpine
|
||||
docker start postgres || docker run --name postgres -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret --network df-network -d postgres:15-alpine
|
||||
|
||||
migratenew:
|
||||
migrate create -ext sql -dir bff/db/migration -seq init_schema
|
||||
@ -43,4 +48,4 @@ server:
|
||||
mock:
|
||||
mockgen -package mockdb -destination bff/db/mock/store.go github.com/itsscb/df/bff/db/sqlc Store
|
||||
|
||||
.PHONY: postgres migratenew createdb dropdb migrateup migratedown sqlc sqlcinit test server, initialize
|
||||
.PHONY: postgres migratenew createdb dropdb migrateup migratedown sqlc sqlcinit test server initialize backend_build_image backend_run reset_docker
|
||||
|
12
README.md
12
README.md
@ -3,10 +3,15 @@
|
||||
To first run the application in your local environment you can use
|
||||
|
||||
```
|
||||
make initialize
|
||||
make network
|
||||
make postgres
|
||||
make backend_build_image
|
||||
make backend_run
|
||||
```
|
||||
|
||||
or run the commands listed in ```Makefile``` under `initialize` ***manually*** with your terminal in the repository root directory.
|
||||
or run those commands, listed in ```Makefile```, ***manually*** with your terminal in the repository root directory.
|
||||
|
||||
***IMPORTANT***: You've got to have *golang-migrate* installed to run the backend.
|
||||
|
||||
# Prerequisites
|
||||
|
||||
@ -53,9 +58,6 @@ You can install it as described [here](https://github.com/golang-migrate/migrate
|
||||
|
||||
Furthermore the binary should be in your `PATH` environment variable.
|
||||
|
||||
The two most used commands are in the `Makefile`:
|
||||
- migrateup
|
||||
- migratedown
|
||||
|
||||
#### Server
|
||||
|
||||
|
16
bff/Dockerfile
Normal file
16
bff/Dockerfile
Normal file
@ -0,0 +1,16 @@
|
||||
# Build stage
|
||||
FROM golang:1.21-alpine3.18 AS builder
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN go build -o main main.go
|
||||
|
||||
# Run stage
|
||||
FROM alpine:3.18
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/main .
|
||||
COPY app.env .
|
||||
ENV DB_SOURCE=postgresql://root:secret@postgres:5432/df?sslmode=disable
|
||||
COPY db/migration ./db/migration
|
||||
|
||||
EXPOSE 8080
|
||||
CMD [ "/app/main" ]
|
@ -13,7 +13,7 @@ import (
|
||||
var testQueries *Queries
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
config, err := util.LoadConfig("../../..")
|
||||
config, err := util.LoadConfig("../..")
|
||||
if err != nil {
|
||||
log.Fatal("cannot load config:", err)
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
config, err := util.LoadConfig("./..")
|
||||
config, err := util.LoadConfig(".")
|
||||
if err != nil {
|
||||
log.Fatal("cannot load config:", err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user