diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7079b99 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +coverage +lib diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 4f37ea3..2cb8687 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -52,6 +52,25 @@ jobs: name: code-coverage-report path: coverage/** + build-docker: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v3 + - name: lint dockerfile + uses: luke142367/Docker-Lint-Action@v1.0.0 + with: + target: Dockerfile + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/setup-buildx-action@v2.5.0 + - name: build docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + tags: ${{ secrets.DOCKERHUB_USERNAME }}/linux-top-parser:latest + code-analysis: runs-on: ubuntu-latest needs: build diff --git a/.github/workflows/release-and-publish-package.yml b/.github/workflows/release-and-publish-package.yml index 2eeb368..74807dd 100644 --- a/.github/workflows/release-and-publish-package.yml +++ b/.github/workflows/release-and-publish-package.yml @@ -13,6 +13,7 @@ on: - major env: + GITHUB_REGISTRY: ghcr.io NODE_VERSION: 18.x jobs: @@ -72,3 +73,19 @@ jobs: run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + + - name: log in to the container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.GITHUB_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/setup-buildx-action@v2.5.0 + - name: publish docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ env.GITHUB_REGISTRY }}/sweetim/linux-top-parser:${{ steps.get_latest_git_tag.outputs.latest_git_tag }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c4c76e8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:18-alpine as builder + +WORKDIR /app +COPY ./src ./src +COPY package.json LICENSE ./ +RUN npm ci +RUN npm run build + +FROM node:18-alpine + +RUN addgroup -S user \ + && adduser -S user -G user + +WORKDIR /app +COPY --from=builder /app/package.json /app/LICENSE ./ +COPY --from=builder /app/lib ./lib +RUN npm install --production + +USER user + +CMD ["node", "./lib/bin.js"]