Skip to content

Commit

Permalink
Merge branch 'ci/setup'
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed May 29, 2024
2 parents fff3efd + 1c60473 commit eea37da
Show file tree
Hide file tree
Showing 9 changed files with 8,218 additions and 44 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: 🚀 Deploy

on:
workflow_dispatch:
push:
branches:
- main
- staging
- ci/setup

concurrency:
group: ${{ github.ref }}-deploy

env:
CI: true

permissions:
id-token: write
contents: write

defaults:
run:
shell: bash

jobs:
deploy:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'

- uses: pnpm/action-setup@v4
with:
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: "🔨 Install dependencies"
run: pnpm install --frozen-lockfile

- name: "👥 Configure AWS Credentials"
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::262732185023:role/github-action-deploy-role
aws-region: eu-west-1
retry-max-attempts: 5

- name: "👥 Login to Amazon ECR"
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: "🔨 Prebuild docker dependencies"
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/arm64
push: true
tags: 262732185023.dkr.ecr.eu-west-1.amazonaws.com/indexer:latest
# Github actions cache
cache-from: type=gha
cache-to: type=gha,mode=max

- name: "🚀 SST Deploy"
run: |
echo "Deploying with stage: prod"
pnpm sst deploy --stage prod
38 changes: 24 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1-debian as base
# Base image is node-22
FROM node:22-slim as base

# Setup pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
RUN corepack install --global [email protected]

# Create app directory
WORKDIR /usr/src/app
COPY . .

# install dependencies into temp directory
# this will cache them and speed up future builds
Expand All @@ -12,21 +18,25 @@ RUN apt-get update
RUN apt-get install -y \
python3 \
build-essential
# Install dependencies
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile --ignore-scripts

# install with --production (exclude devDependencies)
# Install dependencies
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production --ignore-scripts
COPY package.json /temp/prod/
RUN cd /temp/prod && pnpm --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod

# copy production dependencies and source code into final image
FROM base AS release

# Set env to production
ENV NODE_ENV production

# copy production dependencies and source code into final image
COPY . .
COPY --from=install /temp/prod/node_modules node_modules

# Allow node user to everything in the working directory, and switch to it
#RUN chown node:node ./
#USER node

# run the app
USER bun
EXPOSE 42069/tcp
ENTRYPOINT [ "bun", "run", "start" ]
ENTRYPOINT [ "pnpm", "run", "start" ]
33 changes: 33 additions & 0 deletions DockerfileBun
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1-debian as base
WORKDIR /usr/src/app
COPY . .

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
# install python and all the stuff required to build sqlite3
RUN apt-get update
RUN apt-get install -y \
python3 \
build-essential
# Install dependencies
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
# TODO: This is failing cause of better-sqlite3 dependency RAAAGH
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# copy production dependencies and source code into final image
FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules

# run the app
USER bun
EXPOSE 42069/tcp
ENTRYPOINT [ "bun", "run", "start" ]
Binary file removed bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
},
"engines": {
"node": ">=18.14"
}
},
"packageManager": "[email protected]"
}
Loading

0 comments on commit eea37da

Please sign in to comment.