From 5cacc029cf66ce7c34376f6fb1d07f44bea7fd28 Mon Sep 17 00:00:00 2001 From: Alexey Kucherenko Date: Thu, 18 Apr 2024 17:43:01 +0300 Subject: [PATCH] ci: introduce cd (#11) --- .dockerignore | 9 ++++++ .github/workflows/cd.yml | 53 ++++++++++++++++++++++++++++++++ .github/workflows/commitlint.yml | 6 ++-- .github/workflows/test.yml | 2 +- Dockerfile | 6 ++++ commitlint.config.js | 2 +- static/index.html | 2 ++ 7 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/cd.yml create mode 100644 Dockerfile create mode 100644 static/index.html diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0fc4294 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +# Items that don't need to be in a Docker image. +# Anything not used by the build system should go here. +.* +Dockerfile +README.md + +# Artifacts that will be built during image creation. +# This should contain all files created during `npm run build`. +node_modules diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..bb592fb --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,53 @@ +name: Deploy + +on: + release: + types: [prereleased, released] + +concurrency: + cancel-in-progress: false + +env: + ENVIRONMENT: ${{ github.event.action == 'prereleased' && 'staging' || 'production' }} + +jobs: + build-and-push: + name: "Build and push docker image" + runs-on: ubuntu-latest + environment: ${{ env.ENVIRONMENT }} + steps: + - name: Print variables + run: echo "${{ toJSON(vars)}}" + + - name: Print env + run: echo "${{ toJSON(env)}}" + + - name: Print secrets + run: echo "${{ toJSON(secrets)}}" + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build docker image (environment) + run: | + docker build -t ghcr.io/killmenot/github-test-${{ env.ENVIRONMENT }}:${{ github.event.release.tag_name }} -f Dockerfile . + + - name: Push docker image to GitHub Container Registry (environment) + run: | + docker push ghcr.io/killmenot/github-test-${{ env.ENVIRONMENT }}:${{ github.event.release.tag_name }} + + - name: Push docker image to GitHub Container Registry (production > staging) + if: env.ENVIRONMENT == 'production' + run: | + docker push ghcr.io/killmenot/github-test-staging:${{ github.event.release.tag_name }} + + + + diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index 291583f..d0d5e68 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -45,7 +45,9 @@ jobs: if: github.event_name == 'pull_request' run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose - - name: Validate PR title with commitlint - run: ${{ github.event.pull_request.title }} | npx commitlint --version + # TODO: + # - name: Validate PR title with commitlint + # if: github.event_name == 'pull_request' + # uses: JulienKode/pull-request-name-linter-action@v0.5.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6b7f667..758f56a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,4 +7,4 @@ jobs: runs-on: ubuntu-latest steps: - name: Print github context - run: echo "${{ toJSON(github) }}" + run: echo '${{ toJSON(github) }}' diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..626906c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM nginx:1.25.4-alpine + +COPY /static /usr/share/nginx/html +RUN chown nginx.nginx /usr/share/nginx/html/ -R + +EXPOSE 80 diff --git a/commitlint.config.js b/commitlint.config.js index 11ac02c..7035073 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -3,5 +3,5 @@ const test = (r) => r.test.bind(r); module.exports = { defaultIgnores: false, extends: ['@commitlint/config-conventional'], - ignores: [test(/Merge branch (.*?)(in|into) (.*)/)], + ignores: [test(/Merge branch (.*?)/), test(/Merge branch (.*?)(in|into) (.*)/)], }; diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..56db817 --- /dev/null +++ b/static/index.html @@ -0,0 +1,2 @@ +

Hello World

+h1>