hehehe #46
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 | |
# | |
#jobs: | |
# build: | |
# | |
# runs-on: self-hosted | |
# | |
# steps: | |
# - uses: actions/checkout@v4 | |
# - name: Build the Docker image | |
# run: docker compose up -d --build | |
name: Deploy to VPS | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
runs-on: self-hosted | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
# - name: Set up Docker Buildx | |
# uses: docker/setup-buildx-action@v1 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker images | |
run: | | |
docker compose up -d --build | |
docker compose push | |
# - name: Deploy to server | |
# env: | |
# host: ${{ secrets.SERVER_HOST }} | |
# username: ${{ secrets.SERVER_USER }} | |
# SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
# script: | | |
# sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no $USERNAME@$HOST ' | |
# docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} && | |
# | |
# mkdir -p /path/to/your/deployment | |
# cd /path/to/your/deployment | |
# docker-compose pull | |
# docker-compose up -d | |
# ' | |
- name: copy file via ssh key | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USER }} | |
port: 22 | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
source: "docker-compose.yml,.env" | |
target: 'project' #path project | |
- name: Deploy to server | |
env: | |
HOST: ${{ secrets.SERVER_HOST }} | |
USERNAME: ${{ secrets.SERVER_USER }} | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
run: | | |
echo "${SSH_PRIVATE_KEY}" > ssh_key | |
chmod -R 600 ssh_key | |
ssh -i ssh_key -o StrictHostKeyChecking=no $USERNAME@$HOST ' | |
docker login --username ${{ secrets.DOCKER_USERNAME }} --password-stdin ${{ secrets.DOCKER_PASSWORD }} && | |
pwd | |
cd project | |
pwd | |
docker compose pull && | |
docker compose up -d --build | |
' |