Update docker-image.yml #90
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 React App with SSL | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build_and_deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Checkout the code | |
| - name: Checkout Code | |
| uses: actions/checkout@v2 | |
| # Login to Docker Hub | |
| - name: Login to Docker Hub | |
| run: | | |
| echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
| # Build Docker Image | |
| - name: Build Docker Image | |
| run: | | |
| docker build --build-arg SSL_CERT_CHAIN="${{ secrets.SSL_CERT_CHAIN }}" \ | |
| --build-arg SSL_PRIVATE_KEY="${{ secrets.SSL_PRIVATE_KEY }}" \ | |
| -t ${{ secrets.DOCKER_USERNAME }}/webportfolio:latest . | |
| # Push Docker Image | |
| - name: Push Docker Image | |
| run: | | |
| docker push ${{ secrets.DOCKER_USERNAME }}/webportfolio:latest | |
| # Set up SSH Key | |
| - name: Set up SSH Key | |
| uses: webfactory/ssh-agent@v0.5.3 | |
| with: | |
| ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| # Deploy to Server | |
| - name: Deploy to Server | |
| uses: appleboy/ssh-action@v0.1.8 | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| # Pull the latest Docker image | |
| sudo docker pull ${{ secrets.DOCKER_USERNAME }}/webportfolio:latest | |
| # Stop and remove any existing container | |
| sudo docker stop webportfolio || true | |
| sudo docker rm webportfolio || true | |
| # Run the new container with SSL environment variables | |
| sudo docker run -d -p 80:80 -p 443:443 \ | |
| -e SSL_CERT_CHAIN="${{ secrets.SSL_CERT_CHAIN }}" \ | |
| -e SSL_PRIVATE_KEY="${{ secrets.SSL_PRIVATE_KEY }}" \ | |
| --name webportfolio \ | |
| ${{ secrets.DOCKER_USERNAME }}/webportfolio:latest |