Skip to content

Merge pull request #48 from mrmilu/feature/IFMD-10-upgrade-dependencies #8

Merge pull request #48 from mrmilu/feature/IFMD-10-upgrade-dependencies

Merge pull request #48 from mrmilu/feature/IFMD-10-upgrade-dependencies #8

Workflow file for this run

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: |
"env_variables=${{ secrets.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 -d COMPOSE_NAME