Deploy to VM #52
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 to VM | |
on: | |
workflow_dispatch: | |
env: | |
PORT: ${{ secrets.PORT }} | |
MONGO_AUTH_DB: ${{ secrets.MONGO_AUTH_DB }} | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
PROJECT_ID: ${{ secrets.PROJECT_ID }} | |
PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }} | |
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} | |
CLIENT_EMAIL: ${{ secrets.CLIENT_EMAIL }} | |
CLIENT_ID: ${{ secrets.CLIENT_ID }} | |
AUTH_URI: ${{ secrets.AUTH_URI }} | |
TOKEN_URI: ${{ secrets.TOKEN_URI }} | |
AUTH_PROVIDER: ${{ secrets.AUTH_PROVIDER }} | |
CERT_URL: ${{ secrets.CERT_URL }} | |
INSTAMOJO_CLIENT_ID: ${{ secrets.INSTAMOJO_CLIENT_ID }} | |
INSTAMOJO_CLIENT_SECRET: ${{ secrets.INSTAMOJO_CLIENT_SECRET }} | |
INSTAMOJO_BASE_URL: ${{ secrets.INSTAMOJO_BASE_URL }} | |
ALLOWED_CLIENT_URL: ${{ secrets.ALLOWED_CLIENT_URL }} | |
jobs: | |
# build: | |
# uses: dscnitrourkela/project-dates/.github/workflows/build.yml@main | |
# secrets: | |
# USERNAME: ${{ secrets.USERNAME }} | |
# PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }} | |
deploy: | |
runs-on: [self-hosted, dsc-main] | |
defaults: | |
run: | |
shell: bash | |
working-directory: api | |
strategy: | |
matrix: | |
node-version: [16.x] | |
# needs: build | |
steps: | |
# - name: Remove existing env | |
# run: rm .env || true | |
- uses: actions/checkout@v2 | |
- name: Deploy Server | |
uses: actions/setup-node@v2 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Create Env | |
run: | | |
touch .env | |
echo PORT=$PORT >> .env | |
echo DATABASE_URL=$DATABASE_URL >> .env | |
echo MONGO_AUTH_DB=$MONGO_AUTH_DB >> .env | |
echo PROJECT_ID=$PROJECT_ID >> .env | |
echo PRIVATE_KEY_ID=$PRIVATE_KEY_ID >> .env | |
echo PRIVATE_KEY=$PRIVATE_KEY >> .env | |
echo CLIENT_EMAIL=$CLIENT_EMAIL >> .env | |
echo CLIENT_ID=$CLIENT_ID >> .env | |
echo AUTH_URI=$AUTH_URI >> .env | |
echo TOKEN_URI=$TOKEN_URI >> .env | |
echo AUTH_PROVIDER=$AUTH_PROVIDER >> .env | |
echo CERT_URL=$CERT_URL >> .env | |
echo INSTAMOJO_CLIENT_ID=$INSTAMOJO_CLIENT_ID >> .env | |
echo INSTAMOJO_CLIENT_SECRET=$INSTAMOJO_CLIENT_SECRET >> .env | |
echo INSTAMOJO_BASE_URL=$INSTAMOJO_BASE_URL >> .env | |
echo ALLOWED_CLIENT_URL=$ALLOWED_CLIENT_URL >> .env | |
# - name: Pull Docker Image | |
# run: docker pull ghcr.io/${{ github.repository }}:latest | |
- name: Build Docker Image | |
run: docker build -t ghcr.io/${{ github.repository }}:latest . | |
- name: Stop existing container | |
run: docker stop project-dates || true | |
- name: Remove stopped container | |
run: docker rm project-dates || true | |
- name: Start container | |
run: docker run --name=project-dates --env-file=.env -p $PORT:$PORT -d ghcr.io/${{ github.repository }}:latest | |
- name: Remove Unused Images | |
run: docker image prune -f |