Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add make target to start a development env with database and air hot loading #352

Open
1 task done
mingan666 opened this issue Dec 13, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@mingan666
Copy link

Tell us about your feature request

Currently there is no make target that enables me start the database together with air hot loading.
Either I can use make docker-run which does not support air hot loading, or I can use make watch which does not start the database.
I'd like to be able to start a development environment that supports both a database (as a test container like used for the tests or a regular docker image) together with the server with air hot loading support.

Disclaimer

  • I agree
@mingan666 mingan666 added the enhancement New feature or request label Dec 13, 2024
@Ujstor
Copy link
Collaborator

Ujstor commented Dec 15, 2024

We can approach the solution in two different ways. One would be to simply add a target to the Makefile so that when make watch is executed, the database is also spun up:

watch:  docker-run
       @if command -v air > /dev/null; then \
	    air; \
	    echo "Watching...";\
        ...

Alternatively, we can achieve this using a Dockerfile and Docker Compose:
(This is just a code snippet to demonstrate the concept, the database part is not included.)

FROM golang:1.22-alpine AS base

RUN apk add --no-cache make

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .

FROM base AS dev
RUN make build
EXPOSE 5000
CMD [ "sh", "-c", "echo 'y' | make watch" ]

FROM base AS build
RUN make build

FROM alpine:3.20.1 AS prod
WORKDIR /app
COPY --from=build /app/main /app/main
EXPOSE 5000
CMD ["./main"]
services:
  web-dev:
    build:
      context: .
      dockerfile: Dockerfile
      target: dev
    ports:
      - 5000:5000
    volumes:
      - ./:/app

  web-prod:
    build:
      context: .
      dockerfile: Dockerfile
      target: prod
    ports:
      - 5000:5000

# docker compose up  web-dev --build
# docker compose up  web-prod --build

There is also a compose watch option that could be considered as an alternative.

https://docs.docker.com/compose/how-tos/file-watch/

It is a nice issue to solve, so any PRs are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants