From 0d393bbc27702729954c0b319113f36686ac995c Mon Sep 17 00:00:00 2001 From: dice4x4 Date: Thu, 23 Jun 2022 02:28:49 +0400 Subject: [PATCH 1/2] Deploy release --- .github/workflows/deploy-release.yml | 79 ++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .github/workflows/deploy-release.yml diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml new file mode 100644 index 0000000..1cb0019 --- /dev/null +++ b/.github/workflows/deploy-release.yml @@ -0,0 +1,79 @@ +name: Build and deploy release + +concurrency: production + +on: + release: + types: + - released + branches: + - main + tags: + - 'v*' +env: + USERNAME: deploy + HOST: wunder-kammer.ru + PORT: 22 + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + NAME: soroka-backend-prod + +jobs: + deploy: + name: Build and Deploy release + runs-on: ubuntu-latest + env: + POSTGRES_USER: ${{ secrets.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} + POSTGRES_DB: ${{ secrets.POSTGRES_DB }} + DB_PORT: ${{ secrets.DB_PORT }} + DB_HOST: ${{ secrets.DB_HOST }} + DB_DIALECT: postgres + SERVER_PORT: 8000 + ACCESS_TOKEN_LIFETIME: 300000 + REFRESH_TOKEN_LIFETIME: 3600000 + steps: + - name: Checkout latest + uses: actions/checkout@v3 + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=true + prefix= + suffix= + tags: | + type=semver,pattern={{version}} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + + - name: executing remote ssh commands using ssh key + uses: appleboy/ssh-action@master + with: + host: ${{ env.HOST }} + username: ${{ env.USERNAME }} + key: ${{ secrets.WNDRKMR_SSH_KEY }} + port: ${{ env.PORT }} + script: | + echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u dice4x4 --password-stdin + docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + docker rm -f ${{ env.NAME }} + docker run -dp 8084:8000 --network wndrnet --name ${{ env.NAME }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + docker logout + From 12b5fea283f61f266163b560dbea449a02a09ec0 Mon Sep 17 00:00:00 2001 From: dice4x4 Date: Thu, 23 Jun 2022 02:35:35 +0400 Subject: [PATCH 2/2] Rename default branch to `master` in actions --- .github/workflows/deploy-release.yml | 2 +- .github/workflows/deploy-staging.yml | 2 +- .github/workflows/docker-image.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml index 1cb0019..f8e7087 100644 --- a/.github/workflows/deploy-release.yml +++ b/.github/workflows/deploy-release.yml @@ -7,7 +7,7 @@ on: types: - released branches: - - main + - master tags: - 'v*' env: diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 2d46356..6afb978 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -7,7 +7,7 @@ on: types: - closed branches: - - main + - master env: USERNAME: deploy HOST: wunder-kammer.ru diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 7a1e8a4..34dc32e 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,7 +2,7 @@ name: Build Docker Image on: pull_request: - branches: [ "main" ] + branches: [ "master" ] types: ["opened", "reopened", "synchronize"] tags: [ 'v*.*.*' ]