Skip to content

Instantly share code, notes, and snippets.

@redjoker011
Last active April 27, 2024 17:34
Show Gist options
  • Save redjoker011/4a0ddaeb21e96ce9efa579b40c57c531 to your computer and use it in GitHub Desktop.
Save redjoker011/4a0ddaeb21e96ce9efa579b40c57c531 to your computer and use it in GitHub Desktop.
Bitbucket CI/CD Pipeline Config for Vuejs App
# This is a sample build configuration for JavaScript.
# Check our guides at https://confluence.atlassian.com/x/14UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
# Note variables start with `$` are repository variables added to bitbucket repo.
image: node:12.18.2
pipelines:
branches:
development:
- step:
name: "Test and Build"
script:
- ./bin/pipeline_setup.sh
- npm run test:unit:pipeline
- >-
VUE_APP_I18N_LOCALE=$LOCALE
VUE_APP_I18N_FALLBACK_LOCALE=$LOCALE
NODE_ENV=production
npm run build:staging
artifacts:
- dist/**
- step:
name: "Deploy to Staging"
deployment: staging
script:
- RELEASE_DIR=$RELEASE_PATH_STAGING/$(date +%s)
- echo $RELEASE_DIR
- CURRENT_DIR=$DEPLOY_PATH_STAGING/current
- echo $CURRENT_DIR
- pipe: atlassian/ssh-run:0.2.6
variables:
SSH_USER: $SERVER_USER
SERVER: $SERVER_HOST_STAGING
COMMAND: "mkdir ${RELEASE_DIR}"
- pipe: atlassian/scp-deploy:0.3.12
variables:
USER: $SERVER_USER
SERVER: $SERVER_HOST_STAGING
REMOTE_PATH: $RELEASE_DIR
LOCAL_PATH: "dist/**"
- pipe: atlassian/ssh-run:0.2.6
variables:
SSH_USER: $SERVER_USER
SERVER: $SERVER_HOST_STAGING
COMMAND: "rm -rf $CURRENT_DIR; ln -s $RELEASE_DIR $CURRENT_DIR"
- step:
name: "Release Cleanup"
script:
- pipe: atlassian/scp-deploy:0.3.12
variables:
USER: $SERVER_USER
SERVER: $SERVER_HOST_STAGING
REMOTE_PATH: "."
LOCAL_PATH: "bin/release_dir_cleanup.sh"
- pipe: atlassian/ssh-run:0.2.6
variables:
SSH_USER: $SERVER_USER
SERVER: $SERVER_HOST_STAGING
# MODE: "script"
COMMAND: "./release_dir_cleanup.sh $RELEASE_PATH_STAGING"
# COMMAND: "./cleanup.sh $RELEASE_PATH_STAGING"
master:
- step:
name: "Test and Build"
script:
- ./bin/pipeline_setup.sh
- npm run test:unit:pipeline
- >-
VUE_APP_I18N_LOCALE=$LOCALE
VUE_APP_I18N_FALLBACK_LOCALE=$LOCALE
NODE_ENV=production
npm run build:production
artifacts:
- dist/**
- step:
name: "Deploy to Production"
deployment: production
script:
- RELEASE_DIR=$RELEASE_PATH_PROD/$(date +%s)
- echo $RELEASE_DIR
- CURRENT_DIR=$DEPLOY_PATH_PROD/current
- echo $CURRENT_DIR
- pipe: atlassian/ssh-run:0.2.6
variables:
SSH_USER: $SERVER_USER
SERVER: $SERVER_HOST_PROD
COMMAND: "mkdir ${RELEASE_DIR}"
- pipe: atlassian/scp-deploy:0.3.12
variables:
USER: $SERVER_USER
SERVER: $SERVER_HOST_PROD
REMOTE_PATH: $RELEASE_DIR
LOCAL_PATH: "dist/**"
- pipe: atlassian/ssh-run:0.2.6
variables:
SSH_USER: $SERVER_USER
SERVER: $SERVER_HOST_PROD
COMMAND: "rm -rf $CURRENT_DIR; ln -s $RELEASE_DIR $CURRENT_DIR"
- step:
name: "Release Cleanup"
script:
- pipe: atlassian/scp-deploy:0.3.12
variables:
USER: $SERVER_USER
SERVER: $SERVER_HOST_PROD
REMOTE_PATH: "."
LOCAL_PATH: "bin/release_dir_cleanup.sh"
- pipe: atlassian/ssh-run:0.2.6
variables:
SSH_USER: $SERVER_USER
SERVER: $SERVER_HOST_PROD
COMMAND: "./release_dir_cleanup.sh $RELEASE_PATH_PROD"
default:
- step:
caches:
- nodecustom
script: # Modify the commands below to build your repository.
- ./bin/pipeline_setup.sh
- npm run test:unit:pipeline
# Cache Node Modules and Yarn
# https://community.atlassian.com/t5/Bitbucket-questions/Is-Yarn-supported-for-bitbucket-pipelines-caching/qaq-p/650816
definitions:
caches:
nodecustom: ./node_modules
# yarn: /usr/local/share/.cache/yarn
# bin/pipeline-setup.sh
#!/bin/bash
# Assume this script will run into Node Environment
# yarn install
# yarn global add @vue/cli
# Install vue cli via npm
npm i @vue/cli
npm i #install dependencies
# bin/release-cleanup.sh
RELEASES_DIR="$1"
MAX_RELEASES_LENGTH=5 # Max Release Directories
DIRS=()
echo $RELEASES_DIR
result=$(cd $RELEASES_DIR; ls -d */)
echo $result
for i in $result; do DIRS+=("${i%%/}"); done
DIRS=($(echo ${DIRS[*]}| tr " " "\n" | sort -n))
LENGTH=${#DIRS[@]}
INDEX=`expr ${#DIRS[@]} - $MAX_RELEASES_LENGTH`
INDEX=$(( $INDEX < 0 ? 0 : $INDEX ))
echo $DIRS
REMOVABLE_DIRS=()
echo $REMOVABLE_DIRS
for i in "${DIRS[@]}"; do
skip=
for j in "${DIRS[@]:INDEX}"; do
[[ $i == $j ]] && { skip=1; break; }
done
[[ -n $skip ]] || REMOVABLE_DIRS+=("$i")
done
$(cd $RELEASES_DIR; rm -rf ${REMOVABLE_DIRS[@]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment