Skip to content

Fix sharing feature #36

Fix sharing feature

Fix sharing feature #36

Workflow file for this run

name: Deploy
on:
push:
branches:
- main
- develop
- staging
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
default: 'staging'
type: choice
options:
- development
- staging
- production
env:
APP_NAME: artemia-frontend
jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.environment.outputs.env }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine environment
id: environment
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "env=${{ github.event.inputs.environment }}" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "env=production" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" == "refs/heads/staging" ]; then
echo "env=staging" >> $GITHUB_OUTPUT
else
echo "env=development" >> $GITHUB_OUTPUT
fi
- name: Generate image tags
id: meta
run: |
IMAGE_TAG="${{ github.sha }}"
echo "image-tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build Docker image
uses: docker/build-push-action@v5
id: build
with:
context: .
push: true # Push to registry
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}-${{ steps.environment.outputs.env }}:${{ github.sha }}
${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}-${{ steps.environment.outputs.env }}:latest
build-args: |
DEPLOYMENT_ENV=${{ steps.environment.outputs.env }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy-development:
name: Deploy to Development
needs: build
runs-on: ubuntu-latest
if: contains(github.ref, 'develop') || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'development')
environment: development
steps:
- name: Checkout code (for actions)
uses: actions/checkout@v4
- name: Deploy to VM
uses: ./.github/actions/deploy-to-vm
with:
vm-host: ${{ secrets.VM_HOST }}
vm-username: ${{ secrets.VM_USERNAME }}
vm-private-key: ${{ secrets.VM_PRIVATE_KEY }}
image-name: ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}-development
image-tag: ${{ github.sha }}
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-token: ${{ secrets.DOCKER_TOKEN }}
container-name: ${{ env.APP_NAME }}-dev
port: 3001
environment: development
env:
ENV_FILE: ${{ secrets.ENV_FILE }}
deploy-staging:
name: Deploy to Staging
needs: build
runs-on: ubuntu-latest
if: contains(github.ref, 'staging') || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'staging')
environment: staging
steps:
- name: Checkout code (for actions)
uses: actions/checkout@v4
- name: Deploy to VM
uses: ./.github/actions/deploy-to-vm
with:
vm-host: ${{ secrets.VM_HOST }}
vm-username: ${{ secrets.VM_USERNAME }}
vm-private-key: ${{ secrets.VM_PRIVATE_KEY }}
image-name: ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}-staging
image-tag: ${{ github.sha }}
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-token: ${{ secrets.DOCKER_TOKEN }}
container-name: ${{ env.APP_NAME }}-staging
port: 3002
environment: staging
env:
ENV_FILE: ${{ secrets.ENV_FILE }}
deploy-production:
name: Deploy to Production
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production')
environment: production
steps:
- name: Checkout code (for actions)
uses: actions/checkout@v4
- name: Deploy to VM
uses: ./.github/actions/deploy-to-vm
with:
vm-host: ${{ secrets.VM_HOST }}
vm-username: ${{ secrets.VM_USERNAME }}
vm-private-key: ${{ secrets.VM_PRIVATE_KEY }}
image-name: ${{ secrets.DOCKER_USERNAME }}/${{ env.APP_NAME }}-production
image-tag: ${{ github.sha }}
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-token: ${{ secrets.DOCKER_TOKEN }}
container-name: ${{ env.APP_NAME }}-prod
port: 3000
environment: production
env:
ENV_FILE: ${{ secrets.ENV_FILE }}
notify:
name: Send Teams notification
# Notify only when build and production deployment are successful.
needs: [build, deploy-production]
runs-on: ubuntu-latest
if: |
needs.build.result == 'success' && needs.deploy-production.result == 'success'
steps:
- name: Send Teams notification
run: |
curl -X POST "${{ secrets.TEAMS_WEBHOOK_URL }}"