From 7ddf1afcf395d4210f8bd8eeaf66513a654efb85 Mon Sep 17 00:00:00 2001 From: Evgeniy Frolov Date: Thu, 14 Nov 2024 18:46:33 +0300 Subject: [PATCH] docs(buildah): add github actions buildah docs Signed-off-by: Evgeniy Frolov --- bin/configurator/config.yml | 26 ++++++++++++++++++- .../host-runner/linux/buildah/infra.md.liquid | 11 ++++++++ .../linux/buildah/project.md.liquid | 8 ++++++ .../linux/docker/project.md.liquid | 2 +- .../host-runner/linux/buildah/infra.md.liquid | 11 ++++++++ .../linux/buildah/project.md.liquid | 9 +++++++ .../linux/docker/project.md.liquid | 2 +- .../linux/buildah/.github/workflows/prod.yml | 4 +-- .../docker/.github/workflows/cleanup.yml | 20 ++++++++++++++ .../linux/docker/.github/workflows/prod.yml | 23 ++++++++++++++++ .../docker/.helm/templates/deployment.yaml | 16 ++++++++++++ .../linux/docker/.helm/templates/service.yaml | 10 +++++++ .../host-runner/linux/docker/app/Dockerfile | 7 +++++ .../linux/docker/app/package-lock.json | 12 +++++++++ .../host-runner/linux/docker/app/package.json | 8 ++++++ .../host-runner/linux/docker/app/server.js | 14 ++++++++++ .../host-runner/linux/docker/werf.yaml | 6 +++++ 17 files changed, 184 insertions(+), 5 deletions(-) create mode 100644 bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/infra.md.liquid create mode 100644 bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/project.md.liquid create mode 100644 bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/infra.md.liquid create mode 100644 bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/project.md.liquid create mode 100644 examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.github/workflows/cleanup.yml create mode 100644 examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.github/workflows/prod.yml create mode 100644 examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.helm/templates/deployment.yaml create mode 100644 examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.helm/templates/service.yaml create mode 100644 examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/Dockerfile create mode 100644 examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/package-lock.json create mode 100644 examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/package.json create mode 100644 examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/server.js create mode 100644 examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/werf.yaml diff --git a/bin/configurator/config.yml b/bin/configurator/config.yml index 9f796933c..ce9e70b74 100644 --- a/bin/configurator/config.yml +++ b/bin/configurator/config.yml @@ -100,7 +100,7 @@ combinations: - name: "buildBackend" value: "docker" - # github actions simple + # GitHub actions host docker - tabs: - name: "project" includePath: "/configurator/tab/ci/github-actions/simple/host-runner/linux/docker/project.md.liquid" @@ -122,6 +122,30 @@ combinations: - name: "repoType" value: "application" + # GitHub Actions host buildah + - tabs: + - name: "infra" + includePath: "/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/infra.md.liquid" + - name: "project" + includePath: "/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/project.md.liquid" + options: + - name: "usage" + value: "ci" + - name: "ci" + value: "githubActions" + - name: "runnerType" + value: "hostRunner" + - name: "os" + value: "linux" + - name: "buildBackend" + value: "buildah" + - name: "projectType" + value: "simplified" + - name: "sharedCICD" + value: "no" + - name: "repoType" + value: "application" + # gitlab ci cd simple - tabs: - name: "infra" diff --git a/bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/infra.md.liquid b/bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/infra.md.liquid new file mode 100644 index 000000000..ebbf32e63 --- /dev/null +++ b/bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/infra.md.liquid @@ -0,0 +1,11 @@ +### Requirements + +- GitHub; + +- Host to run GitHub Runner + +### Installing the GitHub Runner + +Follow [official instructions](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners) to install the GitHub Runner on your dedicated host. + +{% include configurator/partials/ci/buildah_install.md.liquid %} \ No newline at end of file diff --git a/bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/project.md.liquid b/bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/project.md.liquid new file mode 100644 index 000000000..24379d75f --- /dev/null +++ b/bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/project.md.liquid @@ -0,0 +1,8 @@ +### Configuring CI/CD of the project + +This is how the repository that uses werf for build and deploy might look: + +{% tree_file_viewer '/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/buildah' default_file='.github/workflows/prod.yml' %} + +Extras: + * Add authorization options for `werf cleanup` in the container registry by following [instructions]({{ "/docs/v2/usage/cleanup/cr_cleanup.html#features-of-working-with-different-container-registries" | relative_url }}). diff --git a/bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/docker/project.md.liquid b/bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/docker/project.md.liquid index fdf7697b3..8cf0081c8 100644 --- a/bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/docker/project.md.liquid +++ b/bin/configurator/static/_includes/en/configurator/tab/ci/github-actions/simple/host-runner/linux/docker/project.md.liquid @@ -12,7 +12,7 @@ Save the kubeconfig file to access the Kubernetes cluster as a `KUBECONFIG_BASE6 This is how the repository that uses werf for build and deploy might look: -{% tree_file_viewer '/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/buildah' default_file='.github/workflows/prod.yml' %} +{% tree_file_viewer '/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker' default_file='.github/workflows/prod.yml' %} Extras: * Add authorization options for `werf cleanup` in the container registry by following [instructions]({{ "/docs/v2/usage/cleanup/cr_cleanup.html#features-of-working-with-different-container-registries" | relative_url }}). diff --git a/bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/infra.md.liquid b/bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/infra.md.liquid new file mode 100644 index 000000000..bf797d5ab --- /dev/null +++ b/bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/infra.md.liquid @@ -0,0 +1,11 @@ +### Требования + +* GitHub Actions; + +* Linux-хост для установки GitHub Runner + +### Установка GitHub Runner + +Установите GitHub Runner на выделенный для него хост, следуя [официальным инструкциям](https://docs.github.com/ru/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners). + +{% include configurator/partials/ci/buildah_install.md.liquid %} \ No newline at end of file diff --git a/bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/project.md.liquid b/bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/project.md.liquid new file mode 100644 index 000000000..171497496 --- /dev/null +++ b/bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/buildah/project.md.liquid @@ -0,0 +1,9 @@ +### Конфигурация CI/CD проекта + +Так может выглядеть репозиторий, использующий werf для сборки и развертывания: + +{% tree_file_viewer '/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/buildah' default_file='.github/workflows/prod.yml' %} + +{% capture registry_guide_url %}/docs/v2/usage/cleanup/cr_cleanup.html#%D0%BE%D1%81%D0%BE%D0%B1%D0%B5%D0%BD%D0%BD%D0%BE%D1%81%D1%82%D0%B8-%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D1%8B-%D1%81-%D1%80%D0%B0%D0%B7%D0%BB%D0%B8%D1%87%D0%BD%D1%8B%D0%BC%D0%B8-container-registries{% endcapture %} +Дополнительно: + * Добавьте для `werf cleanup` опции авторизации в container registry, следуя [инструкциям]({{ registry_guide_url | relative_url }}). \ No newline at end of file diff --git a/bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/docker/project.md.liquid b/bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/docker/project.md.liquid index 8686e57d5..f0088a2c3 100644 --- a/bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/docker/project.md.liquid +++ b/bin/configurator/static/_includes/ru/configurator/tab/ci/github-actions/simple/host-runner/linux/docker/project.md.liquid @@ -12,7 +12,7 @@ Так может выглядеть репозиторий, использующий werf для сборки и развертывания: -{% tree_file_viewer '/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/buildah' default_file='.github/workflows/prod.yml' %} +{% tree_file_viewer '/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker' default_file='.github/workflows/prod.yml' %} {% capture registry_guide_url %}/docs/v2/usage/cleanup/cr_cleanup.html#%D0%BE%D1%81%D0%BE%D0%B1%D0%B5%D0%BD%D0%BD%D0%BE%D1%81%D1%82%D0%B8-%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D1%8B-%D1%81-%D1%80%D0%B0%D0%B7%D0%BB%D0%B8%D1%87%D0%BD%D1%8B%D0%BC%D0%B8-container-registries{% endcapture %} Дополнительно: diff --git a/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/buildah/.github/workflows/prod.yml b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/buildah/.github/workflows/prod.yml index bc40dd5cb..ce5018dd3 100644 --- a/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/buildah/.github/workflows/prod.yml +++ b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/buildah/.github/workflows/prod.yml @@ -7,7 +7,7 @@ on: jobs: prod: name: prod - runs-on: ubuntu-latest + runs-on: self-hosted steps: - uses: actions/checkout@v3 with: @@ -20,4 +20,4 @@ jobs: werf converge env: WERF_ENV: prod - WERF_KUBECONFIG_BASE64: ${{ secrets.KUBECONFIG_BASE64 }} + WERF_BUILDAH_MODE: auto \ No newline at end of file diff --git a/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.github/workflows/cleanup.yml b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.github/workflows/cleanup.yml new file mode 100644 index 000000000..52387be90 --- /dev/null +++ b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.github/workflows/cleanup.yml @@ -0,0 +1,20 @@ +name: cleanup +on: + schedule: + - cron: "0 3 * * *" + +jobs: + cleanup: + name: cleanup + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: git fetch --prune --unshallow + + - uses: werf/actions/install@v2 + + - run: | + source "$(werf ci-env github --as-file)" + werf cleanup + env: + WERF_KUBECONFIG_BASE64: ${{ secrets.KUBECONFIG_BASE64 }} diff --git a/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.github/workflows/prod.yml b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.github/workflows/prod.yml new file mode 100644 index 000000000..bc40dd5cb --- /dev/null +++ b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.github/workflows/prod.yml @@ -0,0 +1,23 @@ +name: prod +on: + push: + branches: + - main + +jobs: + prod: + name: prod + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: werf/actions/install@v2 + + - run: | + source "$(werf ci-env github --as-file)" + werf converge + env: + WERF_ENV: prod + WERF_KUBECONFIG_BASE64: ${{ secrets.KUBECONFIG_BASE64 }} diff --git a/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.helm/templates/deployment.yaml b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.helm/templates/deployment.yaml new file mode 100644 index 000000000..7a96bc250 --- /dev/null +++ b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.helm/templates/deployment.yaml @@ -0,0 +1,16 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app +spec: + selector: + matchLabels: + app: app + template: + metadata: + labels: + app: app + spec: + containers: + - name: app + image: {{ .Values.werf.image.app }} diff --git a/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.helm/templates/service.yaml b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.helm/templates/service.yaml new file mode 100644 index 000000000..ea4638c98 --- /dev/null +++ b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/.helm/templates/service.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: app +spec: + selector: + app: app + ports: + - name: app + port: 80 diff --git a/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/Dockerfile b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/Dockerfile new file mode 100644 index 000000000..e4389ffb6 --- /dev/null +++ b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/Dockerfile @@ -0,0 +1,7 @@ +FROM node + +WORKDIR /app +COPY . . +RUN npm ci + +CMD ["node", "server.js"] diff --git a/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/package-lock.json b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/package-lock.json new file mode 100644 index 000000000..8cdc810e6 --- /dev/null +++ b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/package-lock.json @@ -0,0 +1,12 @@ +{ + "name": "app", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "app", + "version": "1.0.0" + } + } +} diff --git a/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/package.json b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/package.json new file mode 100644 index 000000000..786223e06 --- /dev/null +++ b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/package.json @@ -0,0 +1,8 @@ +{ + "name": "app", + "version": "1.0.0", + "main": "server.js", + "scripts": { + "start": "node server.js" + } +} diff --git a/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/server.js b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/server.js new file mode 100644 index 000000000..256e1de63 --- /dev/null +++ b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/app/server.js @@ -0,0 +1,14 @@ +const http = require('http'); + +const hostname = '127.0.0.1'; +const port = 80; + +const server = http.createServer((req, res) => { + res.statusCode = 200; + res.setHeader('Content-Type', 'text/plain'); + res.end('Hello World'); +}); + +server.listen(port, hostname, () => { + console.log(`Server running at http://${hostname}:${port}/`); +}); diff --git a/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/werf.yaml b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/werf.yaml new file mode 100644 index 000000000..398b90f1c --- /dev/null +++ b/examples/configurator/ci-cd/simple/github-actions/host-runner/linux/docker/werf.yaml @@ -0,0 +1,6 @@ +configVersion: 1 +project: myproject +--- +image: app +dockerfile: Dockerfile +context: ./app