Update docker-image.yml #15
This file contains hidden or 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 and Deploy Docker Image to Server | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build: | |
| name: Push Docker Image to Docker Hub and Deploy to Server | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Login to Docker Hub | |
| id: docker-hub | |
| run: | | |
| docker login -u ${{secrets.DOCKER_USERNAME}} -p ${{secrets.DOCKER_PASSWORD}} | |
| - name: Build the Docker Image | |
| id: build-docker-image | |
| run: | | |
| ls -la | |
| docker build . -f Dockerfile -t ${{secrets.DOCKER_USERNAME}}/webportfolio:latest | |
| - name: Push the Docker Image | |
| id: push-docker-image | |
| run: docker push ${{secrets.DOCKER_USERNAME}}/webportfolio:latest | |
| - name: SSH into Server and Deploy Docker Image | |
| id: deploy-to-server | |
| uses: appleboy/ssh-action@v0.1.5 | |
| with: | |
| host: 158.179.29.35 | |
| username: opc | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| # Pull the latest image from Docker Hub | |
| docker pull ${{secrets.DOCKER_USERNAME}}/webportfolio:latest | |
| # Run the new container | |
| docker run -d -p 5173:5173 --name webportfolio ${{secrets.DOCKER_USERNAME}}/webportfolio:latest |