Merge pull request #101 from shonenxnaifu/migrate-to-bun #68
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 Web shonen-dev to Development | |
| # 1 | |
| # Controls when the workflow will run | |
| on: | |
| # Triggers the workflow on push events but only for the master branch | |
| push: | |
| branches: [development] | |
| # Allows you to run this workflow manually from the Actions tab | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Development" | |
| required: true | |
| #2 | |
| env: | |
| IMAGE_NAME: "docker_shonen_dev" | |
| CONTAINER_NAME: "docker_shonen_dev_ctr" | |
| #3 | |
| jobs: | |
| build_and_push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout the repo | |
| uses: actions/checkout@v2 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | |
| with: | |
| images: pawitrawarda/docker_shonen_dev | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | |
| with: | |
| context: . | |
| file: ./Dockerfile.dev.bun | |
| push: true | |
| tags: pawitrawarda/docker_shonen_dev:latest | |
| labels: latest | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build_and_push | |
| steps: | |
| - name: Checkout the repo | |
| uses: actions/checkout@v4 | |
| - name: Create directory on server | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.HOST_KAZUHA }} | |
| username: ${{ secrets.USERNAME }} | |
| key: ${{ secrets.SSHKEY_KAZUHA }} | |
| port: ${{ secrets.PORT }} | |
| passphrase: ${{ secrets.PASSPHRASE_KAZUHA }} | |
| script: | | |
| # Create directory if doesn't exist | |
| sudo mkdir -p /opt/apps-container/personal-web | |
| - name: Copy docker-compose.yml to server | |
| uses: appleboy/scp-action@v1 | |
| with: | |
| host: ${{ secrets.HOST_KAZUHA }} | |
| username: ${{ secrets.USERNAME }} | |
| key: ${{ secrets.SSHKEY_KAZUHA }} | |
| port: ${{ secrets.PORT }} | |
| passphrase: ${{ secrets.PASSPHRASE_KAZUHA }} | |
| source: "./docker-compose.yml" | |
| target: "/opt/apps-container/personal-web/" | |
| - name: Deploy using Docker Compose | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.HOST_KAZUHA }} | |
| username: ${{ secrets.USERNAME }} | |
| key: ${{ secrets.SSHKEY_KAZUHA }} | |
| port: ${{ secrets.PORT }} | |
| passphrase: ${{ secrets.PASSPHRASE_KAZUHA }} | |
| envs: IMAGE_NAME, CONTAINER_NAME | |
| script: | | |
| # Navigate to the directory and deploy | |
| cd /opt/apps-container/personal-web | |
| # Pull latest image | |
| docker compose pull personal-web-dev | |
| # Stop and remove existing container | |
| docker compose down --remove-orphans personal-web-dev | |
| # Start services | |
| docker compose up -d --force-recreate personal-web-dev | |
| # Check status of the containers | |
| docker compose ps | |
| # Remove unused images | |
| docker image prune -f |