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

feat: docker build for controller #190

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.hermit
**/node_modules
**/build
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Cache Gradle
id: cache-gradle
uses: actions/cache@v3
with:
path: ~/.gradle/caches/modules-2
key: ${{ runner.os }}-gradle
- name: Init Hermit
uses: cashapp/activate-hermit@v1
- name: Test
Expand All @@ -22,6 +28,12 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Cache Gradle
id: cache-gradle
uses: actions/cache@v3
with:
path: ~/.gradle/caches/modules-2
key: ${{ runner.os }}-gradle
- name: Init Hermit
uses: cashapp/activate-hermit@v1
- name: Test
Expand Down
25 changes: 22 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:
name: Build Docker Images
jobs:
build:
build-runner:
name: Build Runner Docker Image
runs-on: ubuntu-latest
steps:
Expand All @@ -14,7 +14,7 @@ jobs:
- name: Init Hermit
uses: cashapp/activate-hermit@v1
- name: Build
run: docker build -t $(git rev-parse --short HEAD) -t ghcr.io/tbd54566975/ftl:latest -f Dockerfile.runner .
run: docker build -t $(git rev-parse --short HEAD) -t ghcr.io/tbd54566975/ftl-runner:latest -f Dockerfile.runner .
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
Expand All @@ -23,4 +23,23 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push
if: github.ref == 'refs/heads/main'
run: docker push ghcr.io/tbd54566975/ftl:latest
run: docker push ghcr.io/tbd54566975/ftl-runner:latest
build-controller:
name: Build Controller Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Init Hermit
uses: cashapp/activate-hermit@v1
- name: Build
run: docker build -t $(git rev-parse --short HEAD) -t ghcr.io/tbd54566975/ftl-controller:latest -f Dockerfile.controller .
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push
if: github.ref == 'refs/heads/main'
run: docker push ghcr.io/tbd54566975/ftl-controller:latest
36 changes: 36 additions & 0 deletions Dockerfile.controller
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM ubuntu:22.04 AS builder
RUN apt update
RUN apt install -y curl git

# Copy Hermit bin stubs and install all packages. This is done
# separately so that Docker will cache the tools correctly.
COPY ./bin /src/bin
ENV PATH="/src/bin:$PATH"
WORKDIR /src

# Install Hermit tools so Docker will cache them
RUN hermit install

# Download Go dependencies separately so Docker will cache them
COPY go.mod go.sum ./
RUN go mod download -x

# Build
COPY . /src/
RUN make build/release/ftl-controller

# Finally create the runtime image.
FROM ubuntu:22.04

WORKDIR /root/

COPY --from=builder /src/build/release/ftl-controller .
RUN mkdir deployments

EXPOSE 8892

ENV FTL_CONTROLLER_BIND="http://0.0.0.0:8899"
ENV FTL_CONTROLLER_ADVERTISE="http://127.0.0.1:8899"
ENV FTL_CONTROLLER_DSN="postgres://host.docker.internal/ftl?sslmode=disable&user=postgres&password=secret"

CMD ["/root/ftl-controller"]
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ help: ## This help.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

.PHONY: release
release: build/release/ftl-controller build/release/ftl-runner build/release/ftl
release: build/release/ftl-controller build/release/ftl-runner build/release/ftl ## Build release binaries.

build/release/ftl-controller: console/client/dist/index.html
go build -o $@ -tags release -ldflags "-X main.version=$(VERSION)" ./cmd/$(shell basename $@)
Expand All @@ -62,6 +62,11 @@ docker-runner: ## Build ftl-runner docker images.
docker build --tag ftl-runner --platform=linux/amd64 \
-f Dockerfile.runner .

.PHONY:
docker-controller: ## Build ftl-controller docker images.
docker build --tag ftl-controller --platform=linux/amd64 \
-f Dockerfile.controller .

.PHONY: protosync
protosync: ## Synchronise external protos into FTL repo.
protosync
Expand Down
14 changes: 9 additions & 5 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ import (
)

type Config struct {
Bind *url.URL `help:"Socket to bind to." default:"http://localhost:8892"`
Bind *url.URL `help:"Socket to bind to." default:"http://localhost:8892" env:"FTL_CONTROLLER_BIND"`
Advertise *url.URL `help:"Endpoint the Controller should advertise (use --bind if omitted)." default:"" env:"FTL_RUNNER_ADVERTISE"`
Key model2.ControllerKey `help:"Controller key (auto)." placeholder:"C<ULID>" default:"C00000000000000000000000000"`
DSN string `help:"DAL DSN." default:"postgres://localhost/ftl?sslmode=disable&user=postgres&password=secret"`
DSN string `help:"DAL DSN." default:"postgres://localhost/ftl?sslmode=disable&user=postgres&password=secret" env:"FTL_CONTROLLER_DSN"`
RunnerTimeout time.Duration `help:"Runner heartbeat timeout." default:"10s"`
DeploymentReservationTimeout time.Duration `help:"Deployment reservation timeout." default:"120s"`
ArtefactChunkSize int `help:"Size of each chunk streamed to the client." default:"1048576"`
Expand Down Expand Up @@ -114,7 +115,10 @@ func New(ctx context.Context, dal *dal2.DAL, config Config) (*Service, error) {
clients: map[string]clients{},
key: key,
}
go svc.heartbeatController(ctx, config.Bind)
if config.Advertise.String() == "" {
config.Advertise = config.Bind
}
go svc.heartbeatController(ctx, config.Advertise)
go svc.reapStaleControllers(ctx)
go svc.reapStaleRunners(ctx)
go svc.releaseExpiredReservations(ctx)
Expand Down Expand Up @@ -703,10 +707,10 @@ func (s *Service) reapStaleControllers(ctx context.Context) {
}

// Periodically update the DB with the current state of the controller.
func (s *Service) heartbeatController(ctx context.Context, addr *url.URL) {
func (s *Service) heartbeatController(ctx context.Context, advertiseAddr *url.URL) {
logger := log.FromContext(ctx)
for {
_, err := s.dal.UpsertController(ctx, s.key, addr.String())
_, err := s.dal.UpsertController(ctx, s.key, advertiseAddr.String())
if err != nil {
logger.Errorf(err, "Failed to heartbeat controller")
}
Expand Down
Loading