-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitbucket-pipelines.yml
171 lines (163 loc) · 6.51 KB
/
bitbucket-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
pipelines:
default:
- step: &build-assets
name: Build assets
image: node:lts
caches:
- node
script:
- corepack enable
- yarn install
- yarn run encore production
artifacts:
# defining the artifacts to be passed to each future step.
- public/assets/*
- step:
name: Build and test backend
image: composer:2
caches:
- composer
script:
- composer install
- composer dump-env test
- chmod +x bin/phpunit
- bin/phpunit
artifacts:
# defining the artifacts to be passed to each future step.
- reports/*.txt
custom: # Pipelines that are triggered manually
deploy-dev: # The name that is displayed in the list in the Bitbucket Cloud GUI
- step: *build-assets
- step: &build-release
name: Build release
image: composer:2
caches:
- composer
script:
- composer install
- >-
echo 'APP_SECRET=${ovh_app_secret:-ovh_app_secret-NotFount}' >> '.env.prod.local';
echo 'DATABASE_URL=${ovh_database_url:-ovh_database_url-NotFount}' >> '.env.prod.local';
echo 'BITBUCKET_BUILD=${BITBUCKET_BUILD_NUMBER:-BITBUCKET_BUILD_NUMBER-NotFount}' >> '.env.prod.local';
echo 'WEBSITE_VERSION=${WEBSITE_VERSION:-WEBSITE_VERSION-NotFount}-b${BITBUCKET_BUILD}' >> '.env.prod.local';
echo 'HTTP_CLIENT_API_AUTH_BASIC_GITHUB=${GITHUB_API_CLIENT_AUTH_BASIC:-GITHUB_API_CLIENT_AUTH_BASIC-NotFount}' >> '.env.prod.local';
echo 'HTTP_CLIENT_OAUTH_AUTH_BASIC_BITBUCKET=${BITBUCKET_OAUTH_CLIENT_AUTH_BASIC:-BITBUCKET_OAUTH_CLIENT_AUTH_BASIC-NotFount}' >> '.env.prod.local';
- composer dump-env prod
- mkdir release
- >-
cp -v .env*.php release/;
cp -v composer.json release/;
cp -v *.lock release/;
cp -vr bin/ release/bin/;
cp -vr config/ release/config/;
cp -vr migrations/ release/migrations/;
cp -vr public/ release/public/;
cp -vr scripts/ release/scripts/;
cp -vr src/ release/src/;
cp -vr templates/ release/templates/;
cp -vr translations/ release/translations/;
cp -r vendor/ release/vendor/;
- mkdir upload
- tar -zcvf upload/build_$BITBUCKET_BUILD_NUMBER.tgz release/
artifacts:
# defining the artifacts to be passed to each future step.
- upload/*
- step: &ssh-deploy
name: Deploy to DEV
deployment: test
image: atlassian/default-image:4
caches:
- composer
script:
# Deploy the files to FTP
- pipe: atlassian/ftp-deploy:0.3.7
variables:
USER: $ftp_username
PASSWORD: $ftp_password
SERVER: $ftp_server_host
REMOTE_PATH: /bitbucket_trogon-website
LOCAL_PATH: upload
- >-
echo 'echo "=== Print environment variables ===";' > deploy.sh;
echo 'printenv;' >> deploy.sh;
echo 'echo "=== Unzip the release package ===";' >> deploy.sh;
echo 'cd upload/$RELEASE_DIR;' >> deploy.sh;
echo 'tar -xf $RELEASE_FILE;' >> deploy.sh;
echo 'if [ -f "$WEB_DIR/composer.json" ] ' >> deploy.sh;
echo 'then' >> deploy.sh;
echo ' echo "=== Backup old version ===";' >> deploy.sh;
echo ' mkdir $BACKUP_DIR;' >> deploy.sh;
echo ' mv -v $WEB_DIR/* $BACKUP_DIR/;' >> deploy.sh;
echo ' mv -v $WEB_DIR/.env* $BACKUP_DIR/;' >> deploy.sh;
echo 'fi' >> deploy.sh;
echo 'echo "=== Copy new version to target ===";' >> deploy.sh;
echo 'mv -v release/* $WEB_DIR/;' >> deploy.sh;
echo 'mv -v release/.env* $WEB_DIR/;' >> deploy.sh;
echo 'echo "=== Remove the temp folders ===";' >> deploy.sh;
echo 'rm -r release;' >> deploy.sh;
echo 'if [ -d $BACKUP_DIR ] ' >> deploy.sh;
echo 'then' >> deploy.sh;
echo ' rm -r $BACKUP_DIR;' >> deploy.sh;
echo 'fi' >> deploy.sh;
echo 'echo "=== Clear Symfony cache ===";' >> deploy.sh;
echo 'echo "Print diagnostic information";' >> deploy.sh;
echo 'printenv;' >> deploy.sh;
echo 'echo "Set PHP version for OVH";' >> deploy.sh;
echo 'export PATH=/usr/local/php8.2/bin:/usr/local/bin:/usr/bin:/bin:/homez.106/trogoneuup/bin;' >> deploy.sh;
echo 'which php;' >> deploy.sh;
echo 'php -v;' >> deploy.sh;
echo 'echo "Clean symfony cache bin/console cache:clear";' >> deploy.sh;
echo 'cd $WEB_DIR;' >> deploy.sh;
echo 'chmod +x ./bin/console;' >> deploy.sh;
echo './bin/console cache:clear -q;' >> deploy.sh;
- pipe: atlassian/ssh-run:0.4.1
variables:
SSH_USER: $ssh_username
SERVER: $ssh_server_host
MODE: script
COMMAND: deploy.sh
ENV_VARS: >-
RELEASE_DIR=bitbucket_trogon-website
RELEASE_FILE=build_$BITBUCKET_BUILD_NUMBER.tgz
BACKUP_DIR=~/upload/backup
WEB_DIR=$site_stage_path
- step:
<<: *ssh-deploy
name: Deploy to UAT
deployment: staging
trigger: manual
- step:
<<: *ssh-deploy
name: Deploy to PROD
deployment: production
trigger: manual
deploy-uat:
- step: *build-assets
- step: *build-release
- step:
<<: *ssh-deploy
name: Deploy to UAT
deployment: staging
trigger: manual
- step:
<<: *ssh-deploy
name: Deploy to PROD
deployment: production
trigger: manual
deploy-prod:
- step: *build-assets
- step: *build-release
- step:
<<: *ssh-deploy
name: Deploy to PROD
deployment: production
trigger: manual
definitions:
services:
mysql5:
image: mysql:5.7
variables:
MYSQL_DATABASE: 'pipelines'
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: 'test_user'
MYSQL_PASSWORD: 'test_user_password'