diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..38e0e2e --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +/frontend/node_modules diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e0e7466 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +FROM node:14-alpine3.14 AS node-builder + +RUN apk --no-cache --virtual build-dependencies add \ + g++ \ + make + +WORKDIR /app +COPY frontend/ . +ARG API_URL +ENV REACT_APP_API_URL=$API_URL +RUN yarn install +RUN yarn build + +FROM golang:1.17.3-alpine3.14 as go-builder +ENV GOPATH "" + +RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest + +WORKDIR /app +ADD backend/go.mod backend/go.sum ./ +RUN go mod download +ADD backend/ . +RUN go build -o ./clipper ./cmd/clipper/ + +FROM alpine:3.14 +RUN apk add ffmpeg + +COPY backend/sql/migrations /app/migrations +COPY --from=go-builder /app/clipper /bin/clipper +COPY --from=go-builder /root/go/bin/migrate /bin/migrate +COPY --from=node-builder /app/build /app/assets + +ENV ASSETS_HTTP_BASE_PATH "/app/assets" + +ENTRYPOINT ["/bin/clipper"] diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..3dcda5a --- /dev/null +++ b/deploy.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# +# Build and deploy Clipper. +# +# Dependencies: +# +# docker +# pv (pacman -S pv) +# bzip2 +# +# To run migrations from container: +# +# docker-compose run --no-deps --entrypoint /bin/sh clipper-staging -c '/bin/migrate -path /app/migrations -database $DATABASE_URL up' +# +# TODO: production build +set -ex + +docker build \ + -t netfluxio/clipper-staging:latest \ + --build-arg API_URL=https://clipper-staging.netflux.io \ + . + +docker save netfluxio/clipper-staging:latest | bzip2 | pv | ssh netflux 'bunzip2 | docker load' diff --git a/frontend/.env b/frontend/.env new file mode 100644 index 0000000..994ca22 --- /dev/null +++ b/frontend/.env @@ -0,0 +1 @@ +REACT_APP_API_URL=http://localhost:8888 diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 5bdb360..c8a48f1 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -20,6 +20,8 @@ const thumbnailHeight = 100; const initialViewportSeconds = 10; +const apiURL = process.env.REACT_APP_API_URL || 'http://localhost:8888'; + // Frames represents a selection of audio frames. export interface Frames { start: number; @@ -212,8 +214,6 @@ function millisFromDuration(dur?: Duration): number { return Math.floor(dur.seconds * 1000.0 + dur.nanos / 1000.0 / 1000.0); } -const grpcHost = 'http://localhost:8888'; - export function newRPC(): GrpcWebImpl { - return new GrpcWebImpl(grpcHost, {}); + return new GrpcWebImpl(apiURL, {}); }