Docker compose
This commit is contained in:
30
docker-compose.yml
Normal file
30
docker-compose.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
services:
|
||||||
|
db:
|
||||||
|
build:
|
||||||
|
context: ./database
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
ports:
|
||||||
|
- 55432:5432
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=postgres
|
||||||
|
- POSTGRES_PASSWORD=postgres
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||||
|
interval: 1s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 10
|
||||||
|
machines-app:
|
||||||
|
build:
|
||||||
|
context: ./machines
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
environment:
|
||||||
|
- DBHOST=db
|
||||||
|
- DBPORT=5432
|
||||||
|
- DBNAME=komponiranje
|
||||||
|
- DBUSER=pero
|
||||||
|
- DBPASSWORD=pero.000
|
||||||
|
ports:
|
||||||
|
- 3000:3000
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
3
machines/.dockerignore
Normal file
3
machines/.dockerignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
**/build
|
||||||
|
**/tmp
|
||||||
|
**/.env*
|
||||||
20
machines/Dockerfile
Normal file
20
machines/Dockerfile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# stage 2: build golang backend
|
||||||
|
FROM golang:1.21-alpine3.19 as go-builder
|
||||||
|
|
||||||
|
WORKDIR /go-builder
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
go mod download && \
|
||||||
|
go mod verify && \
|
||||||
|
go build -v -ldflags "-s -w" -o machines-app ./app/main.go
|
||||||
|
|
||||||
|
|
||||||
|
# stage 2: build final container
|
||||||
|
FROM alpine:3.19
|
||||||
|
|
||||||
|
USER $USER
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=go-builder /go-builder/machines-app /app
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app/machines-app"]
|
||||||
@ -2,13 +2,38 @@ EXEC=machines-app
|
|||||||
CONTAINER_NAME=machines-app
|
CONTAINER_NAME=machines-app
|
||||||
IMAGE_NAME=komponiranje-machines-app
|
IMAGE_NAME=komponiranje-machines-app
|
||||||
|
|
||||||
|
|
||||||
run:
|
run:
|
||||||
@air
|
@air
|
||||||
|
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
@go build -ldflags "-s -w" -o ./build/${EXEC} ./app/.
|
@go build -ldflags "-s -w" -o ./build/${EXEC} ./app/.
|
||||||
|
|
||||||
|
|
||||||
upgrade-packages:
|
upgrade-packages:
|
||||||
@go get -u ./...
|
@go get -u ./...
|
||||||
|
|
||||||
|
|
||||||
|
docker-build: clean
|
||||||
|
@docker build \
|
||||||
|
--progress=plain \
|
||||||
|
--tag $(IMAGE_NAME) \
|
||||||
|
.
|
||||||
|
|
||||||
|
|
||||||
|
docker-run:
|
||||||
|
@docker run \
|
||||||
|
--name $(CONTAINER_NAME) \
|
||||||
|
--publish 3000:3000 \
|
||||||
|
--env CONTAINER_NAME="Awesome API server" \
|
||||||
|
--env DBPORT=55432 \
|
||||||
|
--detach \
|
||||||
|
$(IMAGE_NAME)
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
- @docker stop $(CONTAINER_NAME)
|
||||||
|
- @docker rm $(CONTAINER_NAME)
|
||||||
|
- @docker rmi $(IMAGE_NAME)
|
||||||
|
|||||||
Reference in New Issue
Block a user