Skip to content

feat : Update be-autodeploy.yml #69

feat : Update be-autodeploy.yml

feat : Update be-autodeploy.yml #69

Workflow file for this run

name: auto deploy
on:
push:
branches:
- develop/be
jobs:
push_to_registry:
name: Push to ncp container registry
runs-on: ubuntu-latest
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:
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }}
username: ${{ secrets.NCP_ACCESS_KEY }}
password: ${{ secrets.NCP_SECRET_KEY }}
- name: Create config file
run: |
echo "export const awsConfig = ${OBJECT_STORAGE_CONFIG}" > ./be/objectStorage.config.ts
env:
OBJECT_STORAGE_CONFIG: ${{ secrets.OBJECT_STORAGE_CONFIG }}
- name: Create TypeORM config
run: |
mkdir -p ./be/src/configs
echo "import { TypeOrmModuleOptions } from '@nestjs/typeorm';" > ./be/src/configs/typeorm.config.ts
echo "export const typeORMConfig: TypeOrmModuleOptions = ${TYPEORM_CONFIG}" >> ./be/src/configs/typeorm.config.ts
env:
TYPEORM_CONFIG: ${{ secrets.TYPEORM_CONFIG }}
- name: build and push
uses: docker/build-push-action@v3
with:
context: ./be
file: ./be/Dockerfile
push: true
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/nibobnebob:latest
cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/nibobnebob:latest
cache-to: type=inline
pull_from_registry:
name: Connect server ssh and pull from container registry
needs: push_to_registry
runs-on: ubuntu-latest
steps:
- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa.pem
chmod 600 ~/.ssh/id_rsa
- name: SSH Connection to EC2 Instance
run: |
ssh -o "StrictHostKeyChecking=no" -i ~/.ssh/id_rsa.pem ubuntu@${{ secrets.DEV_HOST }} 'echo "Connected to EC2 Instance"'
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/nibobnebob
docker stop my_was_container
docker rm my_was_container
docker run -d -p 8000:8000 -e API_KEY=${{ secrets.DEV_APIKEY }} --name my_was_container --network mynetwork ${{ secrets.NCP_CONTAINER_REGISTRY }}/nibobnebob
docker image prune -f