Update #241
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: CI | |
on: | |
push: | |
branches: [main, dev] | |
pull_request: | |
branches: [main, dev] | |
jobs: | |
docker: | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
no-cache: true | |
rm: true | |
tags: spearx/kaufland-game:main | |
build-args: | | |
SUPABASE_URL=${{ secrets.SUPABASE_URL }} | |
SUPABASE_KEY=${{ secrets.SUPABASE_KEY }} | |
# deploy: | |
# if: github.ref == 'refs/heads/main' | |
# needs: docker | |
# runs-on: ubuntu-latest | |
# | |
# steps: | |
# - uses: actions/checkout@v3 | |
# | |
# - name: Set up SSH | |
# uses: kielabokkie/ssh-key-and-known-hosts-action@v1 | |
# with: | |
# ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
# ssh-host: 18.185.113.51 | |
# | |
# - name: Manually add SSH key to known_hosts | |
# run: | | |
# ssh-keyscan -H 18.185.113.51 >> ~/.ssh/known_hosts | |
# | |
# - name: Remove Docker Compose stack | |
# run: | | |
# echo "Removing previous stack" | |
# ssh ubuntu@18.185.113.51 "docker stack rm kaufland-stack" | |
# | |
# - name: Wait for old stack to be removed | |
# run: | | |
# echo "Waiting for old stack to be removed" | |
# while ssh ubuntu@18.185.113.51 "docker stack ls | grep -q kaufland-stack" | |
# do | |
# echo "Old stack is still present, waiting..." | |
# sleep 5 | |
# done | |
# sleep 5 | |
# | |
# - name: Docker system prune | |
# run: | | |
# echo "Pruning Docker system" | |
# ssh ubuntu@18.185.113.51 "docker system prune -f" | |
# | |
# - name: Start new stack | |
# run: | | |
# echo "Starting new stack" | |
# ssh ubuntu@18.185.113.51 "docker stack deploy -c /home/ubuntu/k-market-caddy/docker-compose.yml kaufland-stack" | |
build-and-deploy: | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: "18" # adjust if you use another version | |
- name: Install pnpm | |
run: npm install -g pnpm | |
- name: Install Dependencies | |
run: pnpm install | |
- name: Build Project | |
run: pnpm build # adjust if your build command is different | |
env: | |
SUPABASE_URL: ${{ secrets.SUPABASE_URL }} | |
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }} | |
- name: Zip the build | |
run: zip -r build.zip .output # adjust the path to your build output | |
- name: Set up SSH | |
uses: kielabokkie/ssh-key-and-known-hosts-action@v1 | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
ssh-host: 18.156.80.97 | |
- name: Add SSH key to known hosts | |
run: | | |
ssh-keyscan -H 18.156.80.97 >> ~/.ssh/known_hosts | |
- name: SCP .zip to the server | |
run: | | |
scp build.zip ubuntu@18.156.80.97:~/. | |
env: | |
SSH_AUTH_SOCK: /tmp/ssh-auth.sock | |
- name: Unzip and Restart Node | |
run: | | |
ssh ubuntu@18.156.80.97 "sudo rm -rf /var/www/html/k-market/web/.output" | |
ssh ubuntu@18.156.80.97 "sudo unzip ~/build.zip -d /var/www/html/k-market/web" | |
ssh ubuntu@18.156.80.97 "sudo systemctl restart k-market.service" | |
# ssh ubuntu@18.185.113.51 "sudo rm -rf ~/demos/kaufland-game/.output" | |
# ssh ubuntu@18.185.113.51 "sudo unzip ~/demos/kaufland-game/build.zip -d ~/demos/kaufland-game" | |
# ssh ubuntu@18.185.113.51 "sudo systemctl restart kaufland-demo" |