From cb598361c01863f057cbf06b1250452fc13f0d55 Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Tue, 9 Aug 2022 01:01:48 +0300 Subject: [PATCH 1/3] Update MySQL service limits --- .env.sample | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.sample b/.env.sample index b21fa7e..6c1fda4 100644 --- a/.env.sample +++ b/.env.sample @@ -16,8 +16,8 @@ CACHE_STORAGE=file JWT_SECRET= JWT_TTL=3600 JWT_REFRESH_TTL=604800 -JWT_PUBLIC_KEY="" -JWT_PRIVATE_KEY="" +JWT_PUBLIC_KEY="{rsa-public-key}" +JWT_PRIVATE_KEY="{rsa-private-key}" DB_HOST=localhost:33060 DB_NAME=cashtrack From 5bd2c1a3ea5ebdb17435574cf3777ac21d254799 Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Tue, 9 Aug 2022 22:03:18 +0300 Subject: [PATCH 2/3] Add deployment pipeline using kubectl --- .github/workflows/release.yml | 61 +++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ac6bdbf..6cf0a41 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,8 +6,10 @@ on: env: REPO: cashtrack/api - CONTAINER_NAME: cashtrack_api - WORKDIR: /var/www/cash-track.app/api + INFRA_REPO: cash-track/infra + INFRA_REPO_REF: main + CLUSTER: k8s-cash-track + NAMESPACE: cash-track jobs: build: @@ -59,6 +61,21 @@ jobs: packages: write steps: + - name: Checkout infra repository + uses: actions/checkout@v2 + with: + repository: ${{ env.INFRA_REPO }} + ref: ${{ env.INFRA_REPO_REF }} + path: deploy + + - name: Install doctl + uses: digitalocean/action-doctl@v2 + with: + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + + - name: Configure kubectl + run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ env.CLUSTER }} + # Extract metadata (tags, labels) for Docker # https://github.com/docker/metadata-action - name: Extract Docker metadata @@ -70,28 +87,22 @@ jobs: tags: | type=semver,pattern={{version}} - # Execute deployment script on the server - # https://github.com/appleboy/ssh-action - - name: Deploy - uses: appleboy/ssh-action@master + - name: Update deployment env: IMAGE: ${{ env.REPO }}:${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} - with: - host: ${{ secrets.PRODUCTION_SSH_HOST }} - username: ${{ secrets.PRODUCTION_SSH_USER }} - key: ${{ secrets.PRODUCTION_SSH_PRIVATE_KEY }} - script: | - cd ${{ env.WORKDIR }} - docker pull ${{ env.IMAGE }} - docker stop ${{ env.CONTAINER_NAME }} - docker run -d \ - --rm \ - --name ${{ env.CONTAINER_NAME }} \ - -p 3002:8080 \ - --net host \ - -v ${{ env.WORKDIR }}/runtime/logs:/app/runtime/logs \ - -v ${{ env.WORKDIR }}/runtime/snapshots:/app/runtime/snapshots \ - --env-file ${{ env.WORKDIR }}/.env \ - ${{ env.IMAGE }} - ./api_run.sh ${{ env.IMAGE }} app.php cache:clean - ./api_run.sh ${{ env.IMAGE }} app.php migrate + run: sed -i 's|${{ env.REPO }}:latest|'${IMAGE}'|' $GITHUB_WORKSPACE/deploy/services/api/deployment.yml + + - name: Update definition + run: kubectl apply -f $GITHUB_WORKSPACE/deploy/services/api/ + + - name: Verify deployment + run: kubectl -n ${{ env.NAMESPACE }} rollout status deployment/api + + - name: Verify service ready + run: kubectl -n ${{ env.NAMESPACE }} wait pods -l app=api --for condition=Ready --timeout=60s + + - name: Clear cache + run: kubectl -n ${{ env.NAMESPACE }} exec deployments/api -it -- php app.php cache:clean + + - name: Clear cache + run: kubectl -n ${{ env.NAMESPACE }} exec deployments/api -it -- php app.php migrate From 4de6bee8da1895dcd3aadd3b1fd259876fcfb2b6 Mon Sep 17 00:00:00 2001 From: Volodymyr Komarov Date: Tue, 9 Aug 2022 22:07:04 +0300 Subject: [PATCH 3/3] Avoid build pipeline on push --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8759117..342da8a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,6 @@ name: build on: - push: pull_request: schedule: - cron: '0 0 * * *'