From 56e2f19972f69bbc7203d3c35e2360c8660f90c5 Mon Sep 17 00:00:00 2001 From: Kai Ehrhardt Date: Thu, 30 Mar 2023 13:34:27 +0200 Subject: [PATCH] chore(container): add initial container wrapper and build action --- .github/workflows/container-build.yml | 45 +++++++++++++++++++++++++++ Dockerfile.ci | 30 ++++++++++++++++++ Dockerfile => Dockerfile.dev | 0 docker-compose.yml | 4 ++- docs/guides-ci-setup.md | 18 +++++++++++ 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/container-build.yml create mode 100644 Dockerfile.ci rename Dockerfile => Dockerfile.dev (100%) diff --git a/.github/workflows/container-build.yml b/.github/workflows/container-build.yml new file mode 100644 index 0000000000..b68da9a0ee --- /dev/null +++ b/.github/workflows/container-build.yml @@ -0,0 +1,45 @@ +name: container build +on: + push: + tags: + - '**' + branches: + - '**' + - '!master' + schedule: + - cron: '0 0 * * *' +jobs: + container-build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Log into registry + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: commitlint/commitlint + tags: | + type=semver,pattern={{version}} + type=edge,branch=master + type=ref,event=branch + type=sha,prefix=,format=short + - name: Build and push container image + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile.ci + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + # disable arm build for now, because of https://github.com/nodejs/docker-node/issues/1335 + platforms: linux/amd64 #,linux/arm64 diff --git a/Dockerfile.ci b/Dockerfile.ci new file mode 100644 index 0000000000..babe60d0db --- /dev/null +++ b/Dockerfile.ci @@ -0,0 +1,30 @@ +FROM docker.io/library/node:18-buster AS builder +WORKDIR /src +COPY . ./ +RUN yarn install && \ + yarn run build && \ + # Commit lint CLI packages + npm pack @commitlint/cli && \ + npm pack @commitlint/config-validator && \ + npm pack @commitlint/ensure && \ + npm pack @commitlint/execute-rule && \ + npm pack @commitlint/format && \ + npm pack @commitlint/is-ignored && \ + npm pack @commitlint/lint && \ + npm pack @commitlint/load && \ + npm pack @commitlint/message && \ + npm pack @commitlint/parse && \ + npm pack @commitlint/read && \ + npm pack @commitlint/resolve-extends && \ + npm pack @commitlint/rules && \ + npm pack @commitlint/to-lines && \ + npm pack @commitlint/top-level && \ + npm pack @commitlint/types && \ + # Default commitlint config + npm pack @commitlint/config-conventional + +FROM docker.io/library/node:18-buster +COPY --from=builder /src/*.tgz ./ +RUN npm install -g *.tgz && \ + rm -rf *.tgz +ENTRYPOINT ["commitlint"] diff --git a/Dockerfile b/Dockerfile.dev similarity index 100% rename from Dockerfile rename to Dockerfile.dev diff --git a/docker-compose.yml b/docker-compose.yml index 5e57122d7a..401320c97e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,9 @@ version: '3' services: commitlint: - build: . + build: + context: . + dockerfile: Dockerfile.dev image: marionebl/commitlint-cubicle ports: - '8443:8443' diff --git a/docs/guides-ci-setup.md b/docs/guides-ci-setup.md index 6b3ed628c6..870fa924ab 100644 --- a/docs/guides-ci-setup.md +++ b/docs/guides-ci-setup.md @@ -121,12 +121,30 @@ workflows: ## GitLab CI ```yaml +stages: ["lint","build","test"] lint:commit: + image: registry.hub.docker.com/library/node:alpine stage: lint + before_script: + - apk add --no-cache git + - npm install --save-dev @commitlint/config-conventional @commitlint/cli script: - echo "${CI_COMMIT_MESSAGE}" | npx commitlint ``` +## GitLab CI with pre-build container + +```yaml +stages: ["lint","build","test"] +lint:commit: + image: + name: registry.hub.docker.com/commitlint/commitlint:latest + entrypoint: [""] + stage: lint + script: + - echo "${CI_COMMIT_MESSAGE}" | commitlint +``` + ### 3rd party integrations #### [Codemagic](https://codemagic.io/)