Skip to content

Instantly share code, notes, and snippets.

@imamnurhy
Created February 5, 2025 11:25
Show Gist options
  • Save imamnurhy/9656bbf6c66c9cc76860353d8660cb12 to your computer and use it in GitHub Desktop.
Save imamnurhy/9656bbf6c66c9cc76860353d8660cb12 to your computer and use it in GitHub Desktop.
CI/CD
image: imamnurhy/sshxhelper:latest
stages:
- prepare
- test
- deploy
- release
variables:
VERSION: "2.2.0"
ROOT_DIR: "/var/www/html/public_html"
test:
image: php:7.3.33-cli
stage: test
rules:
- when: never
before_script:
- echo "Installing PHP dependencies..."
- apt-get update && apt-get install -y zip git unzip libpng-dev libzip-dev
- echo "Installing PHP extensions..."
- docker-php-ext-install gd zip
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer install --no-interaction --prefer-dist
- echo "Setting up Laravel application..."
- cp .env.example .env
- php artisan key:generate
script:
- echo "🔥 Running tests..."
- ./vendor/bin/phpunit
- echo "🥳 Tests complete!"
deploy_to_staging:
stage: deploy
script:
- echo "🐣 Deploying to staging..."
- sshx $SSH_USER@$SSH_HOST -p $SSH_PASSWORD --port $SSH_PORT --exec "
cd $ROOT_DIR;
cp .env.dev .env;
git reset --hard;
git fetch origin;
git checkout dev || git checkout -b dev origin/dev;
git pull --rebase origin dev"
- echo "Deployment complete!"
only:
- dev
deploy_to_production:
stage: deploy
when: manual
script:
- echo "🚀 Deploying to production..."
- sshx $SSH_USER@$SSH_HOST -p $SSH_PASSWORD --port $SSH_PORT --exec "
cd $ROOT_DIR;
cp .env.prod .env;
git reset --hard;
git fetch origin;
git checkout main || git checkout -b main origin/main;
git pull origin main;
deploy push --soft;"
- echo 'Deployment complete!';
only:
- main
release_job:
image: registry.gitlab.com/gitlab-org/release-cli:latest
stage: release
needs:
- job: deploy_to_production
rules:
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- echo "Release application..."
release:
name: "Release v$VERSION"
description: "Release for version v$VERSION"
tag_name: "v$VERSION"
ref: "$CI_COMMIT_SHA"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment