Skip to content

Commit

Permalink
ci: add caching (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Oct 27, 2022
1 parent 9da4606 commit 638ec8e
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 167 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**/.gitkeep
**/.DS_Store
.dockerignore
Dockerfile*
docker/Dockerfile*
docker-compose*.yml
README.md
certs/
Expand All @@ -22,6 +22,7 @@ dist/
prisma/pg-data/data-*

# named volumes
.husky/
.next/
node_modules/

Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/build-images.yml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
on:
push:
branches:
- "**"
- "!main"

name: check
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- uses: pnpm/action-setup@v2.2.4
name: Install pnpm
id: pnpm-install
with:
version: latest
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build
94 changes: 78 additions & 16 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,49 @@ on:
- main
name: release-please
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- uses: pnpm/action-setup@v2.2.4
name: Install pnpm
id: pnpm-install
with:
version: latest
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build

release-please:
outputs:
release_tag: ${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}
release_created: ${{ steps.release.outputs.release_created }}
needs: check
runs-on: ubuntu-latest
steps:
- name: Release
Expand All @@ -14,47 +56,67 @@ jobs:
release-type: node
command: manifest

build-and-push:
needs: release-please
strategy:
matrix:
platform: [linux/amd64, linux/arm64]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
if: ${{ steps.release.outputs.release_created }}

# https://github.com/docker/setup-qemu-action#usage
if: ${{ needs.release-please.outputs.release_created }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
if: ${{ steps.release.outputs.release_created }}
if: ${{ matrix.platform == 'linux/arm64' && needs.release-please.outputs.release_created }}

- name: Set up Docker Build
id: buildx
uses: docker/setup-buildx-action@v2
if: ${{ steps.release.outputs.release_created }}
if: ${{ needs.release-please.outputs.release_created }}

- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
if: ${{ steps.release.outputs.release_created }}
if: ${{ needs.release-please.outputs.release_created }}

- name: Login to Docker hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
if: ${{ steps.release.outputs.release_created }}
if: ${{ needs.release-please.outputs.release_created }}

- name: Build and push
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-${{ matrix.platform }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ matrix.platform }}-buildx-
if: ${{ needs.release-please.outputs.release_created }}

- name: Build
uses: docker/build-push-action@v3
with:
context: .
file: docker/Dockerfile
push: true
# Possible architectures
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
platforms: linux/amd64,linux/arm64
push: ${{ needs.release-please.outputs.release_created }}
platforms: ${{ matrix.platform }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/kaizoku:latest
${{ secrets.DOCKERHUB_USERNAME }}/kaizoku:v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}
${{ secrets.DOCKERHUB_USERNAME }}/kaizoku:v${{ needs.release-please.outputs.release_tag }}
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}
if: ${{ steps.release.outputs.release_created }}
ghcr.io/${{ github.repository }}:v${{ needs.release-please.outputs.release_tag }}
if: ${{ needs.release-please.outputs.release_created }}

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
if: ${{ needs.release-please.outputs.release_created }}
6 changes: 4 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# syntax = docker/dockerfile:experimental

FROM ghcr.io/linuxserver/baseimage-ubuntu:jammy as base

RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
Expand Down Expand Up @@ -29,8 +31,8 @@ WORKDIR /app
COPY prisma ./
COPY package.json pnpm-lock.yaml ./

RUN pnpm i --frozen-lockfile --prod --ignore-scripts && \
prisma generate
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
pnpm install --frozen-lockfile

##### BUILDER

Expand Down
2 changes: 1 addition & 1 deletion docker/root/etc/cont-init.d/40-config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cd /app

prisma migrate deploy
pnpm prisma migrate deploy

mkdir -p /config/.config

Expand Down
10 changes: 2 additions & 8 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import withBundleAnalyzer from '@next/bundle-analyzer';

const bundleAnalyzer = withBundleAnalyzer({
enabled: process.env.ANALYZE === 'true',
});

/**
* Don't be scared of the generics here.
* All they do is to give us autocompletion when using this.
Expand All @@ -13,11 +7,11 @@ const bundleAnalyzer = withBundleAnalyzer({
* @constraint {{import('next').NextConfig}}
*/
function defineNextConfig(config) {
return bundleAnalyzer(config);
return config;
}

export default defineNextConfig({
reactStrictMode: false,
reactStrictMode: true,
swcMinify: true,
staticPageGenerationTimeout: 99999,
// Next.js i18n docs: https://nextjs.org/docs/advanced-features/i18n-routing
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
"@mantine/modals": "^5.5.6",
"@mantine/next": "^5.5.6",
"@mantine/notifications": "^5.5.6",
"@mantine/nprogress": "^5.5.6",
"@mantine/spotlight": "^5.5.6",
"@next/bundle-analyzer": "^12.3.1",
"@prisma/client": "4.5.0",
"@tabler/icons": "^1.106.0",
"@tanstack/react-query": "^4.12.0",
Expand All @@ -57,7 +55,6 @@
"express": "^4.18.2",
"framer-motion": "^7.6.1",
"mantine-datatable": "^1.7.9",
"moment": "^2.29.4",
"next": "12.3.1",
"node-telegram-bot-api": "^0.59.0",
"pino": "^8.6.1",
Expand Down
Loading

0 comments on commit 638ec8e

Please sign in to comment.