updated packages and removed unnecessary whitespaces #43
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: Build, Push, and Deploy Docker Image | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-push-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Generate .env file | |
run: | | |
echo "NEXT_PUBLIC_OPEN_AI_API_KEY=${{ secrets.NEXT_PUBLIC_OPEN_AI_API_KEY }}" >> .env | |
- name: Build and Push Docker Image | |
run: | | |
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/motto:latest -f Dockerfile . | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/motto:latest | |
- name: Deploy to Server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
script: | | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/motto:latest | |
docker stop motto || true | |
docker rm motto || true | |
docker run -d --name motto --restart=unless-stopped -p 3009:3000 ${{ secrets.DOCKERHUB_USERNAME }}/motto:latest |