Bump send and express in /server (#13) #40
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 on AWS EC2 By Docker | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "server/**" | |
defaults: | |
run: | |
working-directory: "server" | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build an Image from Server | |
run: docker build -t video-hub-server . | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Tag my image | |
run: docker tag video-hub-server ${{ secrets.DOCKERHUB_USERNAME }}/video-hub-server | |
- name: Push to Docker Hub | |
run: docker push ${{secrets.DOCKERHUB_USERNAME}}/video-hub-server | |
deploy: | |
needs: build_and_push | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Create Private Key | |
run: | | |
mkdir ~/.ssh/ | |
echo "${{secrets.MY_PRIVATE_KEY}}" > ~/.ssh/video-key.pem | |
chmod 400 ~/.ssh/video-key.pem | |
- name: SSH to EC2 && Run the Docker Image | |
run: | | |
ssh -i "~/.ssh/video-key.pem" -o StrictHostKeyChecking=no [email protected] << EOF | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/video-hub-server | |
if docker ps | grep -q video_hub_container; then | |
docker restart video_hub_container | |
else | |
echo "URL_DB=${{ secrets.URL_DB }}" > .env | |
docker run -dp 5001:5000 --env-file .env --name video_hub_container ${{ secrets.DOCKERHUB_USERNAME }}/video-hub-server | |
fi | |
EOF |