-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reintroduces dockerfiles etc
- Loading branch information
Showing
10 changed files
with
342 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@haishin/frontend': minor | ||
'@haishin/backend': minor | ||
--- | ||
|
||
Playing around with fly migration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,61 +46,221 @@ jobs: | |
publishedPackages: ${{ steps.changesets.outputs.publishedPackages }} | ||
publishedPackageNames: ${{ toJSON(fromJSON(steps.changesets.outputs.publishedPackages).*['name']) }} | ||
|
||
publish-frontend: | ||
needs: create-release-pr | ||
name: Publish frontend | ||
build-frontend: | ||
name: Build frontend | ||
runs-on: ubuntu-latest | ||
if: | | ||
needs.create-release-pr.outputs.hasChangesets == 'false' && ( | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/tsconfig') == true || | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/utils') == true || | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/frontend') == true | ||
) | ||
if: | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
- name: ⬇️ Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup bun | ||
uses: oven-sh/setup-bun@v1 | ||
- name: 👀 Read app name | ||
uses: SebRollen/[email protected] | ||
id: app_name | ||
with: | ||
file: 'apps/frontend/fly.toml' | ||
field: 'app' | ||
|
||
- name: Install dependencies | ||
run: bun install | ||
- name: 🐳 Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
with: | ||
version: v0.9.1 | ||
|
||
- name: Install Railway | ||
run: npm i -g @railway/cli | ||
# Setup cache | ||
- name: ⚡️ Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Deploy | ||
run: railway up --service ${{ secrets.RAILWAY_FRONTEND_SERVICE_ID }} | ||
- name: 🔑 Fly Registry Auth | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: registry.fly.io | ||
username: x | ||
password: ${{ secrets.FLY_API_TOKEN }} | ||
|
||
- name: 🐳 Docker build | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
file: apps/frontend/Dockerfile | ||
push: true | ||
tags: registry.fly.io/${{ steps.app_name.outputs.value }}:${{ | ||
github.ref_name }}-${{ github.sha }} | ||
build-args: | | ||
BACKEND_URL=${{ secrets.BACKEND_URL }} | ||
COMMIT_SHA=${{ github.sha }} | ||
DEEPL_API_KEY=${{ secrets.DEEPL_API_KEY }} | ||
OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} | ||
TURBO_TEAM=${{ secrets.TURBO_TEAM }} | ||
TURBO_TOKEN=${{ secrets.TURBO_TOKEN }} | ||
WS_URL=${{ secrets.WS_URL }} | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new | ||
|
||
# This ugly bit is necessary if you don't want your cache to grow forever | ||
# till it hits GitHub's limit of 5GB. | ||
# Temp fix | ||
# https://github.com/docker/build-push-action/issues/252 | ||
# https://github.com/moby/buildkit/issues/1896 | ||
- name: 🚚 Move cache | ||
run: | | ||
rm -rf /tmp/.buildx-cache | ||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | ||
deploy-frontend: | ||
name: 🚀 Deploy Frontend | ||
runs-on: ubuntu-latest | ||
needs: [create-release-pr, build-frontend] | ||
steps: | ||
- name: 🛑 Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
|
||
- name: ⬇️ Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: 👀 Read app name | ||
uses: SebRollen/[email protected] | ||
id: app_name | ||
with: | ||
file: 'apps/frontend/fly.toml' | ||
field: 'app' | ||
|
||
- name: 🚀 Deploy Staging | ||
if: needs.create-release-pr.outputs.hasChangesets == 'true' | ||
uses: superfly/[email protected] | ||
with: | ||
args: | ||
'deploy --app ${{ steps.app_name.outputs.value }}-staging --config | ||
./apps/frontend/fly.toml --image registry.fly.io/${{ | ||
steps.app_name.outputs.value }}:${{ github.ref_name }}-${{ | ||
github.sha }}' | ||
env: | ||
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }} | ||
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} | ||
|
||
publish-backend: | ||
needs: create-release-pr | ||
name: Publish backend | ||
- name: 🚀 Deploy Production | ||
if: | | ||
needs.create-release-pr.outputs.hasChangesets == 'false' && ( | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/tsconfig') == true || | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/utils') == true || | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/frontend') == true | ||
) | ||
uses: superfly/[email protected] | ||
with: | ||
args: 'deploy --config ./apps/frontend/fly.toml --image | ||
registry.fly.io/${{ steps.app_name.outputs.value }}:${{ | ||
github.ref_name }}-${{ github.sha }}' | ||
env: | ||
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} | ||
|
||
build-backend: | ||
name: Build backend | ||
runs-on: ubuntu-latest | ||
if: | | ||
needs.create-release-pr.outputs.hasChangesets == 'false' && ( | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/tsconfig') == true || | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/utils') == true || | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/backend') == true | ||
) | ||
if: | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
- name: ⬇️ Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup bun | ||
uses: oven-sh/setup-bun@v1 | ||
- name: 👀 Read app name | ||
uses: SebRollen/[email protected] | ||
id: app_name | ||
with: | ||
file: 'apps/backend/fly.toml' | ||
field: 'app' | ||
|
||
- name: Install dependencies | ||
run: bun install | ||
- name: 🐳 Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
with: | ||
version: v0.9.1 | ||
|
||
- name: Install Railway | ||
run: npm i -g @railway/cli | ||
# Setup cache | ||
- name: ⚡️ Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Deploy | ||
run: railway up --service ${{ secrets.RAILWAY_BACKEND_SERVICE_ID }} | ||
- name: 🔑 Fly Registry Auth | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: registry.fly.io | ||
username: x | ||
password: ${{ secrets.FLY_API_TOKEN }} | ||
|
||
- name: 🐳 Docker build | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
file: apps/backend/Dockerfile | ||
push: true | ||
tags: registry.fly.io/${{ steps.app_name.outputs.value }}:${{ | ||
github.ref_name }}-${{ github.sha }} | ||
build-args: | | ||
COMMIT_SHA=${{ github.sha }} | ||
TURBO_TEAM=${{ secrets.TURBO_TEAM }} | ||
TURBO_TOKEN=${{ secrets.TURBO_TOKEN }} | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new | ||
|
||
# This ugly bit is necessary if you don't want your cache to grow forever | ||
# till it hits GitHub's limit of 5GB. | ||
# Temp fix | ||
# https://github.com/docker/build-push-action/issues/252 | ||
# https://github.com/moby/buildkit/issues/1896 | ||
- name: 🚚 Move cache | ||
run: | | ||
rm -rf /tmp/.buildx-cache | ||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | ||
deploy-backend: | ||
name: 🚀 Deploy backend | ||
runs-on: ubuntu-latest | ||
needs: [create-release-pr, build-backend] | ||
steps: | ||
- name: 🛑 Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
|
||
- name: ⬇️ Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: 👀 Read app name | ||
uses: SebRollen/[email protected] | ||
id: app_name | ||
with: | ||
file: 'apps/backend/fly.toml' | ||
field: 'app' | ||
|
||
- name: 🚀 Deploy Staging | ||
if: needs.create-release-pr.outputs.hasChangesets == 'true' | ||
uses: superfly/[email protected] | ||
with: | ||
args: | ||
'deploy --app ${{ steps.app_name.outputs.value }}-staging --config | ||
./apps/backend/fly.toml --image registry.fly.io/${{ | ||
steps.app_name.outputs.value }}:${{ github.ref_name }}-${{ | ||
github.sha }}' | ||
env: | ||
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} | ||
|
||
- name: 🚀 Deploy Production | ||
if: | | ||
needs.create-release-pr.outputs.hasChangesets == 'false' && ( | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/tsconfig') == true || | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/utils') == true || | ||
contains(needs.create-release-pr.outputs.publishedPackageNames, '@haishin/backend') == true | ||
) | ||
uses: superfly/[email protected] | ||
with: | ||
args: 'deploy --config ./apps/backend/fly.toml --image | ||
registry.fly.io/${{ steps.app_name.outputs.value }}:${{ | ||
github.ref_name }}-${{ github.sha }}' | ||
env: | ||
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }} | ||
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} | ||
|
||
cleanup-old-release-tags: | ||
needs: create-release-pr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
FROM node:18-alpine AS node | ||
FROM oven/bun:alpine AS bun | ||
|
||
FROM base AS builder | ||
RUN apk add --no-cache libc6-compat | ||
RUN apk update | ||
RUN pip3 install streamlink | ||
WORKDIR /app | ||
RUN yarn global add turbo | ||
COPY . . | ||
RUN turbo prune --scope @haishin/backend --docker | ||
|
||
# Add lockfile and package.json's of isolated subworkspace | ||
FROM bun AS installer | ||
WORKDIR /app | ||
|
||
# First install the dependencies (as they change less often) | ||
COPY .gitignore .gitignore | ||
COPY --from=builder /app/out/json/ . | ||
COPY --from=builder /app/out/bun.lockb ./bun.lockb | ||
RUN bun install --production | ||
|
||
# Use build args to enable remote caching | ||
ARG TURBO_TEAM | ||
ENV TURBO_TEAM=$TURBO_TEAM | ||
|
||
ARG TURBO_TOKEN | ||
ENV TURBO_TOKEN=$TURBO_TOKEN | ||
|
||
# Build the project | ||
COPY --from=builder /app/out/full/ . | ||
RUN bunx turbo run build --filter=backend... | ||
|
||
# Run the project | ||
FROM bun AS runner | ||
RUN apk add --no-cache g++ make py3-pip ffmpeg | ||
RUN apk update | ||
RUN pip3 install streamlink | ||
WORKDIR /app | ||
COPY --from=installer /app . | ||
|
||
CMD ["bun", "apps/backend/src/index.ts"] | ||
|
||
EXPOSE 3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
app = "personal-haishin-be" | ||
primary_region = "lhr" | ||
kill_signal = "SIGINT" | ||
kill_timeout = "5s" | ||
|
||
[http_service] | ||
internal_port = 8080 | ||
auto_stop_machines = true | ||
auto_start_machines = true | ||
min_machines_running = 0 | ||
processes = ["app"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.