From f21be45fef7aee1cb12e5389b236b3e7b8bca034 Mon Sep 17 00:00:00 2001 From: Tomachi <8929706+book000@users.noreply.github.com> Date: Wed, 21 Sep 2022 23:30:53 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20docker=E3=82=B5=E3=83=9D=E3=83=BC?= =?UTF-8?q?=E3=83=88=20(#142)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: dockerใ‚ตใƒใƒผใƒˆ * ci: fix shellcheck --- .github/workflows/actionlint.yml | 26 +++++++++++++ .github/workflows/ci.yml | 52 ------------------------- .github/workflows/docker.yml | 66 ++++++++++++++++++++++++++++++++ .github/workflows/nodejs-ci.yml | 12 +++--- Dockerfile | 15 ++++++++ docker-compose.yml | 11 ++++++ entrypoint.sh | 6 +++ 7 files changed, 130 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/actionlint.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 entrypoint.sh diff --git a/.github/workflows/actionlint.yml b/.github/workflows/actionlint.yml new file mode 100644 index 00000000..d83803c8 --- /dev/null +++ b/.github/workflows/actionlint.yml @@ -0,0 +1,26 @@ +name: Actionlint with reviewdog + +on: + push: + branches: + - main + - master + pull_request: + +jobs: + actionlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Run ationlint (Push) + if: ${{ github.event_name == 'push' }} + run: | + bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) + ./actionlint -color + + - name: Run actionlint (Pull-request) + if: ${{ github.event_name == 'pull_request' }} + uses: reviewdog/action-actionlint@v1 + with: + fail_on_error: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 6912435a..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: ci - -on: - push: - branches: - - main - - master - pull_request: - branches: - - main - - master - -jobs: - ci: - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [ubuntu-latest] - node: [16] - - steps: - - name: Checkout ๐Ÿ›Ž - uses: actions/checkout@master - - - name: Setup node env ๐Ÿ— - uses: actions/setup-node@v3.4.1 - with: - node-version: ${{ matrix.node }} - check-latest: true - - - name: Get yarn cache directory path ๐Ÿ›  - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - - name: Cache node_modules ๐Ÿ“ฆ - uses: actions/cache@v3 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install dependencies ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป - run: yarn - - - name: Run linter ๐Ÿ‘€ - run: yarn lint - - - name: Run compile ๐Ÿ—๏ธ - run: yarn compile diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..35946d17 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,66 @@ +# ไปปๆ„ใฎใƒฌใ‚ธใ‚นใƒˆใƒชใซ Docker image ใ‚’ๅ…ฌ้–‹orใƒ“ใƒซใƒ‰ใ™ใ‚‹ใ€‚ +# master/mainใฎใƒ—ใƒƒใ‚ทใƒฅๆ™‚ใ€ใƒ—ใƒซใƒชใ‚ฏใฎไฝœๆˆใƒปๆ›ดๆ–ฐๆ™‚ใ€ใƒชใƒชใƒผใ‚นๆ™‚ใซๅ‹•ไฝœใ™ใ‚‹ใ€‚ + +name: Docker + +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + release: + types: + - published + +env: + REGISTRY: ghcr.io + DOCKER_USERNAME: ${{ github.actor }} + DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} + IMAGE_NAME: ${{ github.repository }} + PLATFORMS: linux/amd64,linux/arm64 + +jobs: + job: + name: Docker build + runs-on: ubuntu-latest + + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + install: true + + - name: Login to ${{ env.REGISTRY }} + if: github.event_name == 'release' + uses: docker/login-action@v2.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.DOCKER_USERNAME }} + password: ${{ env.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4.0.1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3.1.1 + with: + context: . + push: ${{ github.event_name == 'release' }} + platforms: ${{ env.PLATFORMS }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/nodejs-ci.yml b/.github/workflows/nodejs-ci.yml index bcab9213..fde65c19 100644 --- a/.github/workflows/nodejs-ci.yml +++ b/.github/workflows/nodejs-ci.yml @@ -33,12 +33,12 @@ jobs: - name: ๐Ÿ“ƒ Check package.json definition id: package-json run: | - compile=$(cat package.json | jq '.scripts | has("compile")') - build=$(cat package.json | jq '.scripts | has("build")') - generate=$(cat package.json | jq '.scripts | has("generate")') - package=$(cat package.json | jq '.scripts | has("package")') - lint=$(cat package.json | jq '.scripts | has("lint")') - test=$(cat package.json | jq '.scripts | has("test")') + compile=$(jq '.scripts | has("compile")' package.json) + build=$(jq '.scripts | has("build")' package.json) + generate=$(jq '.scripts | has("generate")' package.json) + package=$(jq '.scripts | has("package")' package.json) + lint=$(jq '.scripts | has("lint")' package.json) + test=$(jq '.scripts | has("test")' package.json) echo "compile: $compile" echo "build: $build" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f38736a1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM node:16 as builder + +WORKDIR /app + +COPY package.json . +COPY yarn.lock . +RUN yarn install && \ + yarn cache clean + +COPY src/ src/ +COPY tsconfig.json . + +COPY entrypoint.sh . + +ENTRYPOINT [ "/app/entrypoint.sh" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..b794dbff --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.8' + +services: + app: + build: . + # image: ghcr.io/jaoafa/jaotanChatLogger3:latest + volumes: + - type: bind + source: ./config/ + target: /app/config/ + init: true \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 00000000..62d43a9e --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +while : +do + yarn build || true +done \ No newline at end of file