-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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 -p 3001:3001 ${{ secrets.DOCKERHUB_USERNAME }}/motto:latest |