Update #238
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 [email protected] "docker stack rm kaufland-stack" | |
# | |
# - name: Wait for old stack to be removed | |
# run: | | |
# echo "Waiting for old stack to be removed" | |
# while ssh [email protected] "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 [email protected] "docker system prune -f" | |
# | |
# - name: Start new stack | |
# run: | | |
# echo "Starting new stack" | |
# ssh [email protected] "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 [email protected]:~/. | |
env: | |
SSH_AUTH_SOCK: /tmp/ssh-auth.sock | |
- name: Unzip and Restart Node | |
run: | | |
ssh [email protected] "sudo rm -rf /var/www/html/k-market/web/.output" | |
ssh [email protected] "sudo unzip ~/build.zip -d /var/www/html/k-market/web" | |
ssh [email protected] "sudo systemctl restart k-market.service" | |
# ssh [email protected] "sudo rm -rf ~/demos/kaufland-game/.output" | |
# ssh [email protected] "sudo unzip ~/demos/kaufland-game/build.zip -d ~/demos/kaufland-game" | |
# ssh [email protected] "sudo systemctl restart kaufland-demo" |