feat(shared): apply vertical slice architecture to shared (#28) #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy using SSH | |
on: | |
push: | |
branches: | |
- develop | |
- master | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: "${{ github.repository }}" | |
HUSKY: 0 | |
jobs: | |
build: | |
environment: ${{ github.ref_name == 'master' && 'production' || 'staging'}} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Metadata Extraction for Main Image | |
id: meta_main | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=${{ github.ref_name }} | |
- name: Build and Push Main Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: "{{defaultContext}}" | |
push: true | |
file: Dockerfile | |
tags: "${{ steps.meta_main.outputs.tags }}" | |
labels: ${{ steps.meta_main.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
secrets: | | |
"next_env_variables=${{ secrets.NEXT_ENV_VARIABLES}}" | |
deploy: | |
environment: ${{ github.ref_name == 'master' && 'production' || 'staging'}} | |
runs-on: ubuntu-latest | |
needs: [build] | |
steps: | |
- name: Deploy to Staging | |
uses: appleboy/[email protected] | |
env: | |
PROJECT_PATH: ${{ vars.PROJECT_PATH }} | |
COMPOSE_FILE: ${{ vars.COMPOSE_FILE }} | |
with: | |
host: ${{ vars.REMOTE_HOST }} | |
username: ${{ vars.REMOTE_USER}} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: 22 | |
script_stop: true | |
envs: PROJECT_PATH,COMPOSE_FILE | |
script: | | |
export COMPOSE_INTERACTIVE_NO_CLI=1 | |
cd $PROJECT_PATH | |
set -euxo pipefail | |
git pull | |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
docker-compose -f ${{ vars.COMPOSE_FILE }} pull COMPOSE_NAME | |
docker-compose -f ${{ vars.COMPOSE_FILE }} up --force-recreate -d --remove-orphans COMPOSE_NAME |