diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml new file mode 100644 index 0000000..f8e7087 --- /dev/null +++ b/.github/workflows/deploy-release.yml @@ -0,0 +1,79 @@ +name: Build and deploy release + +concurrency: production + +on: + release: + types: + - released + branches: + - master + 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 + 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*.*.*' ]