Deploy From Gitlab To FTP Server

Create file gitlab-ci.yml in gitlab

variables:
  HOST: "yourFTPServer"
  USERNAME: "yourFTPServerUsername"
  PASSWORD: "yourFTPServerPassword"

deploy:
  script:
    - apt-get update -qq && apt-get install -y -qq lftp
    - lftp -c "set ftp:ssl-allow no; open -u $USERNAME,$PASSWORD $HOST; mirror -Rnev ./ ./htdocs --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
  only:
    - master

NOTE: Make sure to change host, username, password and directory name where to deploy code

Ref: https://stackoverflow.com/questions/49632077/use-gitlab-pipeline-to-push-data-to-ftpserver

Docker Cheat Sheet

To run docker image

docker run -p 8080:80 -v /c/xampp/htdocs/dockerdemo:/var/www/html -d php:8-apache

OR

docker run -p 8080:80 --name docker-apache -v /c/xampp/htdocs/dockerdemo:/var/www/html:ro -d php:8-apache

To run docker image in interactive mode

docker container run -it <docker-image> /bin/bash

To List all images

docker images
docker images -q

To List all container

docker ps
docker ps -a
docker ps -aq

To remove image

docker rmi imagename

OR

docker rmi @(docker ps -aq)

To remove container

docker rm <container-name>

OR

docker rm @(docker ps -aq)

OR

docker rm -f @(docker ps -aq)

To stop container

docker stop <container-name>

OR

docker stop @(docker ps -aq)

Hosting project on InfinityFree

Create account on InfinityFree : https://app.infinityfree.net/login
Note down account, MySQL and FTP details

Download FileZilla Client : https://filezilla-project.org/download.php?platform=win64

Export database table : SQL Cheat Sheet (codeinsightacademy.com)

Go to control panel/ databases/phpmyadmin
Create database and import database table in phpmyadmin of infinityfree

Connect to infinityfree server using FTP credentials via FileZilla Client
Once connection is established upload project folder from local site to /htdocs of remote site

Change the database connection credentials (MYSQL username, password, database_name) in project as per MYSQL credentials of infinityfree.

Your project is hosted. refresh the browser and check.

Install Jenkins on Ubuntu

sudo apt update
sudo apt install default-jdk default-jre
javac
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c "echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list"
sudo apt update
sudo apt install jenkins
sudo service jenkins start
sudo service jenkins status

Open Browser and hit following url

http://localhost:8080/

To view default initial password

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Install recommended Plugins. Make sure Git Plugin is installed

Username: admin
Password: Shift + 5
Full name: Administrator

Jenkins URL: http://localhost:8080/
Or
http://youripaddress:8080/
Or
http://yourdomain:8080/

Create New Item (New project for build)

Create release_project.sh file

rsync -av --exclude-from='.releaseignore' <src_dir_path> <dest_dir_path>

Add files and directories entries in .releaseignore file to skip rsync

node_modules
.git
private_documents

After creating freestyle project if you face any permission issue then try one of the following solutions

sudo su -
vim /etc/sudoers

Add following entry at end of file

#add jenkins as sudoer
jenkins        ALL=(ALL)       NOPASSWD: ALL

OR add user to the group

sudo usermod -a -G sudo jenkins

Ref:
medium.com
stackoverflow

Git Ftp

NOTE: Run all commands from your projects root directory

#onetime
sudo apt-get install git-ftp

#onetime NOTE: PLEASE CHANGE WITH YOUR FTP SERVER URL
git config git-ftp.url "ftpupload.net"

#onetime NOTE: PLEASE CHANGE WITH YOUR FTP USERNAME
git config git-ftp.user "ftp-username"

#onetime NOTE: PLEASE CHANGE WITH YOUR FTP PASSWORD
git config git-ftp.password "ftp-password"

#onetime
git config git-ftp.syncroot .

#onetime
git ftp init --remote-root htdocs

git ftp push --remote-root htdocs

if you want to ignore files then create .git-ftp-ignore and add entries in this file

Ref:

https://www.codegrepper.com/code-examples/shell/git+ftp+empty+string+is+not+a+valid+pathspec.+please+use+.+instead+if+you+meant+to+match+all+paths

https://www.zyxware.com/articles/4192/how-to-deploy-files-from-a-git-repository-via-ftp

https://github.com/git-ftp/git-ftp

https://zoomadmin.com/HowToInstall/UbuntuPackage/git-ftp

https://github.com/git-ftp/git-ftp/blob/master/INSTALL.md#debian-ubuntu-and-others-using-apt

https://git-ftp.github.io/

https://github.com/git-ftp/git-ftp/blob/master/man/git-ftp.1.md