I would like to solve this at a small VPS Provider:
Github worflow, when pushed files to GitHub, then "GH workflows" copies the php files to the live VPS server.
How can I copy them?
.github/workflows/vps-deploy-prod.yml:
name: vps-deploy-prod
on:
push:
branches:
- master
jobs:
build: 'VPS Run Deploy'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: action/checkout#master
- name: 'Deploy'
run: make vps-run-deploy
The Makefile:
##### VPS specific target
vps-run-deploy:
?? copy files via ssh scp...?
You might consider the GitHub action appleboy/scp-action
GitHub Action for copying files and artifacts via SSH.
Here is an example in this project: renatomh/gobarber-backend/.github/workflows/main.yml:
# Copy the repository to the directory on the server/VPS used for the application
- name: Copy dist to VPS
uses: appleboy/scp-action#master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
# Selecting all folders except "node_modules"
source: ".,!node_modules"
# The path is based on the directory where the user logged into the server starts
target: "~/app/gobarber-backend"
Related
So what I am trying to do is to organize my ci workflow. I have a self-hosted runner that is my personal computer. Since the workflow files is getting too large I am thinking about reducing the size by having different workflow files instead.
so this is my files so far:
name: "Pipeline"
run-name: ${{ github.actor }} just pushed.
on:
schedule:
- cron: "0 2 * * *"
push:
branches-ignore:
- "docs/*"
tags:
- "v*"
workflow_dispatch:
inputs:
cc_platform:
description: "Input of branch name to build metalayers."
required: true
default: "dev"
jobs:
build:
runs-on: self-hosted
name: Build job.
steps:
- name: Checking out the repository.
uses: actions/checkout#v3
- name: Settings Credentials.
uses: webfactory/ssh-agent#v0.6.0
with:
ssh-private-key: ${{ secrets.SSH_KEY_CC }}
- name: Creating config file.
run:
touch conf
- name: Removing old folders & running build script.
run: |
if [[ -d "my_folder" ]]; then rm -rf my_folder; fi
./build
- name: Generate a zip file of artifacts.
uses: actions/upload-artifact#v3
with:
name: art_${{ github.sha }}
path: |
.*.rootfs.wic.xz
.*.rootfs.manifest
if-no-files-found: error
so what I want to do it to have the artifacts and the build step in their own workflow file. But it does give me som concersn.
Will each workflow file get run in their own runner?
Do they share memory?
I am pretty new for github actions workflow. I have the following question.
What I have:
Have a repo with subfolders folder1/dotnet and folder2/dotnet
What I want to Achieve:
I want to crate github workflow which will lint only folder1 and folder 2 when new code is pushed to specific folder
Currently bellow code lints entire repo
name: pr_dotnet
on:
push:
paths:
- "folder1/dotnet/**"
- "folder2/dotnet/**"
jobs:
lint:
name: Lint dotnet specific folders
runs-on: ubuntu-latest
strategy:
matrix: { dir: ['/folder1/dotnet', 'folder2/dotnet'] }
steps:
- name: Checkout code
uses: actions/checkout#v3
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
- name: MegaLinter
uses: oxsecurity/megalinter/flavors/dotnet#v6.12.0
working-directory: ${{matrix.dir}}
- name: Archive linted artifacts
if: ${{ success() }} || ${{ failure() }}
uses: actions/upload-artifact#v2
with:
name: MegaLinter reports
path: |
megalinter-reports
mega-linter.log
You can run MegaLinter with a sub-workspace as root using variable DEFAULT_WORKSPACE
DEFAULT_WORKSPACE: mega-linter-runner
- name: MegaLinter
uses: oxsecurity/megalinter/flavors/dotnet#v6.12.0
env:
DEFAULT_WORKSPACE: ${{matrix.dir}}
As MegaLinter won't browse at upper lever than DEFAULT_WORKSPACE, you may need to define one .mega-linter.yml config files by root workspace, or use EXTENDS to store the shared configuration online
I'm kinda beginner with CI/CD, but I wrote a code that deploys Vue/Vite project to Ubuntu VPS. But, it's not as it should be. So what am I doing actually?
First as usual, installing the project and building it.
jobs:
build:
name: "Build"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Install
run: yarn
- name: Build
run: yarn build
So the problem is when that passes. I'm connecting to ssh like:
deploy:
name: "Deploy"
needs: project_setup
runs-on: ubuntu-latest
steps:
- name: Deploy to server
uses: appleboy/ssh-action#master
env:
GIT_REPO: Comet-Frontend
GIT_SSH: ${{ github.repositoryUrl }}
with:
host: ${{ secrets.VPS_IP }}
username: ${{ secrets.VPS_USER }}
password: ${{ secrets.VPS_PASSWORD }}
port: ${{ secrets.VPS_PORT }}
envs: GIT_SSH, GIT_REPO
and at the very bottom:
script: |
cd /var/www/vue
git pull
ls
yarn
yarn build
cp -R /root/Frontend/dist /var/www/vue
So I would like to define ssh connection once and run those scripts separately with different step names. Is that possible or I have to connect to ssh for every step?
If each step needs SSH to access either a remote repository URL or your VPS target server, then yes, you would need SSH to each step.
The alternative being to copy a deployment script to the server (through SSH): the steps included in that script could be executed directly on that server (where the script has been copied). No need for SSH then for that script execution, since it is already at target.
I was using the following configuration to deploy Yii2 applications with GitHub actions:
name: Build and Deploy - DEV
on:
push:
branches:
- development
jobs:
build:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout#master
- name: Setup Enviroment
uses: shivammathur/setup-php#v2
with:
php-version: '7.2'
- name: Install Packages
run: composer install --no-dev --optimize-autoloader
- name: Deploy to Server
uses: yiier/yii2-base-deploy#master
with:
user: github
host: ${{ host }}
path: ${{ path }}
owner: github
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
- name: Apply migration
run: php yii migrate --interactive=0
It worked quite well, but now is giving this error:
Current runner version: '2.285.1'
Operating System
Virtual Environment
Virtual Environment Provisioner
GITHUB_TOKEN Permissions
Secret source: Actions
Prepare workflow directory
Prepare all required actions
Getting action download info
Error: Unable to resolve action `yiier/yii2-base-deploy#master`, repository not found
Appears that yiier/yii2-base-deploy#master no longer existis.
Anyone knows a replacer?
Thanks!
Thanks to SiZE comment i remember I had fork the original repo.
I have a custom Jekyll site which is working fine on local.
I would like to deploy my builded site to my hosting environment. Via FTP with github actions is working fine with this: https://github.com/SamKirkland/FTP-Deploy-Action
This is the FTP workflow:
on: push
name: Publish Website
jobs:
FTP-Deploy-Action:
name: FTP-Deploy-Action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2.1.0
with:
fetch-depth: 2
- name: FTP-Deploy-Action
uses: SamKirkland/FTP-Deploy-Action#3.1.1
with:
ftp-server: ${{ secrets.FTP_HOST }}
ftp-username: ${{ secrets.FTP_USER }}
ftp-password: ${{ secrets.FTP_PASSWORD }}
local-dir: _site
git-ftp-args: --changed-only
I tried with the _site folder and and action is run with every commit when the _site is not ignored.
So the best, If I am not comitting the _site page, that will do the GitHub server. I found this action: https://github.com/marketplace/actions/jekyll-actions
My test workflow:
on: push
name: Testing the GitHub Pages building
jobs:
jekyll:
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout#v2
# Use GitHub Actions' cache to shorten build times and decrease load on servers
- uses: actions/cache#v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
# Standard usage
- uses: humarci/jekyll-action#1.0.0
# FTP maybe from here
This is what I currently use, which I found from The World According to Mike Blog.
This uses ncftp which allows you to upload files via ftp easily.
name: Build & Upload Site
# Run on pushes to the master branch
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-ruby#v1
with:
ruby-version: '2.7'
# Install the gems in the gemfile & install ncftp
- name: Setup Environment.
run: |
bundle install
sudo apt-get install -y ncftp
# Build the site
- name: Build Site with Jekyll.
run: JEKYLL_ENV=production bundle exec jekyll build
# Looks kind of complicated but just uploads the content of _site folder to the ftp server. It does not upload the _site folder itself.
- name: Upload site to FTP.
env:
ftp_location: ${{ secrets.FTP_LOCATION }} # Pass in required secrets.
ftp_username: ${{ secrets.FTP_USERNAME }}
ftp_password: ${{ secrets.FTP_PASSWORD }}
run: |
ncftpput -R -v -u "$ftp_username" -p "$ftp_password" $ftp_location / _site/*