From 870efe5862e54e6cbfcf9b3eb84e23b28bbba1ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Andrei?= Date: Thu, 23 Nov 2023 11:08:04 -0300 Subject: [PATCH] Deploy to kitconcept cluster --- .dockerignore | 2 + .github/workflows/image.yml | 58 +++++++++++++++++++++++++++++ .github/workflows/manual_deploy.yml | 49 ++++++++++++++++++++++++ Dockerfile | 55 +++++++++++++++++++++++++++ Makefile | 29 +++++++++++++++ devops/stack/pastanaga-io.yml | 34 +++++++++++++++++ 6 files changed, 227 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/image.yml create mode 100644 .github/workflows/manual_deploy.yml create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 devops/stack/pastanaga-io.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e5452bb --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.github +devops \ No newline at end of file diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml new file mode 100644 index 0000000..fa2fca3 --- /dev/null +++ b/.github/workflows/image.yml @@ -0,0 +1,58 @@ +name: Build Docker Image + +on: + push: + workflow_dispatch: + +env: + IMAGE_NAME: ghcr.io/kitconcept/pastanaga-io + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.IMAGE_NAME }} + labels: | + org.label-schema.docker.cmd=docker run -d -p 80:80 ${{ env.IMAGE_NAME }}:latest + flavor: + latest=false + tags: | + type=ref,event=branch + type=sha + type=raw,value=latest,enable={{is_default_branch}} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v4 + with: + platforms: linux/amd64 + context: frontend/ + file: frontend/Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: $${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/manual_deploy.yml b/.github/workflows/manual_deploy.yml new file mode 100644 index 0000000..c2153ea --- /dev/null +++ b/.github/workflows/manual_deploy.yml @@ -0,0 +1,49 @@ +name: Manual Deployment of pastanaga.io + +on: + workflow_dispatch: + + +jobs: + + meta: + runs-on: ubuntu-latest + outputs: + ENVIRONMENT: ${{ steps.vars.outputs.ENVIRONMENT }} + STACK_NAME: ${{ steps.vars.outputs.STACK_NAME }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set Env Vars + id: vars + run: | + ENVIRONMENT=${{ vars.LIVE_ENV }} + echo "ENVIRONMENT=${ENVIRONMENT}" >> $GITHUB_OUTPUT + echo "STACK_NAME=${ENVIRONMENT//./-}" >> $GITHUB_OUTPUT + + deploy: + if: ${{ github.ref == 'refs/heads/main' }} + needs: + - meta + runs-on: ubuntu-latest + environment: ${{ needs.meta.outputs.ENVIRONMENT }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Deploy to cluster + uses: kitconcept/docker-stack-deploy@v1.2.0 + with: + registry: "ghcr.io" + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + remote_host: ${{ secrets.DEPLOY_HOST }} + remote_port: ${{ secrets.DEPLOY_PORT }} + remote_user: ${{ secrets.DEPLOY_USER }} + remote_private_key: ${{ secrets.DEPLOY_SSH }} + stack_file: devops/stacks/${{ needs.meta.outputs.ENVIRONMENT }}.yml + stack_name: ${{ needs.meta.outputs.STACK_NAME }} + stack_param: ${{ github.ref_name }} + env_file: ${{ secrets.ENV_FILE }} + deploy_timeout: 480 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a9dc002 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +# syntax=docker/dockerfile:1 +FROM node:14-slim as base +RUN <