Skip to content

Workflow file for this run

name: server-deploy
on:
# pull_request:
# types: [closed]
# branches:
# - development
push:
branches:
- test/env
jobs:
docker-image-push:
# if: github.event.pull_request.merged == true
name: Push to container registry
runs-on: ubuntu-latest
strategy:
matrix:
service: [api-gateway, auth, user, inbox, mail-integrator]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to NCP Container Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.NCP_ACCESS_KEY }}
password: ${{ secrets.NCP_SECRET_KEY }}
- name: Set Docker image tag and environment file
id: vars
run: |
echo "IMAGE_TAG=prod" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./apps/Dockerfile.app
push: true
tags: ${{ secrets.NCP_CONTAINER_REGISTRY_URL }}/${{ matrix.service }}:${{ env.IMAGE_TAG }}
build-args: |
PKG_NAME=@apps/${{ matrix.service }}
PORT=3000
pull-n-run-docker-compose:
name: Move docker-compose file to remote server and compose docker containers
needs: docker-image-push
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set Docker image tag and environment file
id: vars
run: |
echo "ENV_FILE=.env.prod" >> $GITHUB_ENV
echo "DOCKER_COMPOSE_FILE=docker-compose-prod.yaml" >> $GITHUB_ENV
- name: Create .env file for remote server
run: |
echo "${{ secrets.PROD_ENV }}" > ${{ env.ENV_FILE }}
- name: Copy docker-compose file
uses: garygrossgarten/github-action-scp@release
with:
local: ./${{ env.DOCKER_COMPOSE_FILE }}
remote: apps/${{ env.DOCKER_COMPOSE_FILE}}
host: ${{ secrets.NCP_SERVER_HOST }}
username: ${{ secrets.NCP_SERVER_USERNAME }}
password: ${{ secrets.NCP_SERVER_PASSWORD }}
- name: Copy .env file to remote server
uses: garygrossgarten/github-action-scp@release
with:
# local: ./.env
# remote: apps/.env
local: ${{ env.ENV_FILE }}
remote: apps/${{ env.ENV_FILE }}
host: ${{ secrets.NCP_SERVER_HOST }}
username: ${{ secrets.NCP_SERVER_USERNAME }}
password: ${{ secrets.NCP_SERVER_PASSWORD }}
- name: Access to remote server via SSH and run docker-compose
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.NCP_SERVER_HOST }}
username: ${{ secrets.NCP_SERVER_USERNAME }}
password: ${{ secrets.NCP_SERVER_PASSWORD }}
port: 22
script: |
docker-compose -f apps/${{ env.DOCKER_COMPOSE_FILE}} down
docker-compose -f apps/${{ env.DOCKER_COMPOSE_FILE}} pull
docker-compose -f apps/${{ env.DOCKER_COMPOSE_FILE}} up -d