Skip to content

Commit

Permalink
ci & cd
Browse files Browse the repository at this point in the history
  • Loading branch information
ITJesse committed Jan 15, 2023
1 parent 92054f9 commit b12c14e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/cache
/dist
node_modules
39 changes: 39 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build
on:
workflow_dispatch:
push:
branches:
- main
jobs:
build:
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
runs-on: [self-hosted, docker]
steps:
- uses: actions/checkout@v3
- uses: mr-smithers-excellent/docker-build-push@v5
name: Build Global & push Docker image
with:
image: kemono/image-optimizer
addLatest: true
registry: registry.ap-northeast-1.aliyuncs.com
dockerfile: deploy/Dockerfile
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

deploy:
needs: [push]
runs-on: [self-hosted, docker]
steps:
- uses: actions/checkout@v3
- name: Deploy Global
run: |
GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")
cp docker-compose.sample.yml /tmp/docker-compose-${GIT_HASH}.yml
sed -i "s/{{GIT-SHA}}/${GIT_HASH}/g" /tmp/docker-compose.yml
SERVER=("web01" "web02")
parallel "ssh {}.jp.internal.abo.network 'mkdir -p /root/image-optimizer'" ::: "${SERVER[@]}"
parallel scp /tmp/docker-compose-${GIT_HASH}.yml {}.jp.internal.abo.network:/root/image-optimizer/ ::: "${SERVER[@]}"
parallel "ssh {}.jp.internal.abo.network 'cd /root/image-optimizer && docker compose up -d'" ::: "${SERVER[@]}"
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Install dependencies only when needed
FROM node:18-alpine AS deps
RUN apk add --no-cache libc6-compat python3 make g++ bash
WORKDIR /app
COPY package.json yarn.lock* ./
RUN yarn --frozen-lockfile

FROM node:18-alpine AS runner-deps
RUN apk add --no-cache libc6-compat python3 make g++ bash
WORKDIR /app
COPY package.json yarn.lock* ./
RUN yarn --frozen-lockfile --production

FROM node:18-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . ./
RUN yarn build

FROM node:18-alpine AS runner
WORKDIR /app
COPY --from=runner-deps /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY package.json yarn.lock* ./
COPY optimizer.config.example.js ./optimizer.config.js

ENV NODE_ENV production

EXPOSE 3100

ENV PORT 3100

CMD ["yarn", "start"]
19 changes: 19 additions & 0 deletions docker-compose.sample.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3'

services:
kemono-games-search:
image: registry.ap-northeast-1.aliyuncs.com/kemono/image-optimizer:{{GIT-SHA}}
restart: always
deploy:
resources:
limits:
memory: 200M
ports:
- 8150:3000
extra_hosts:
- 'host.docker.internal:host-gateway'
environment:
- PORT=3000
volumes:
- ./cache:/app/cache
- ./optimizer.config.js:/app/optimizer.config.js

0 comments on commit b12c14e

Please sign in to comment.