-
Notifications
You must be signed in to change notification settings - Fork 1
/
bitbucket-pipelines.yml
177 lines (164 loc) · 6.05 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
172
173
174
175
176
177
image: node:lts-buster
definitions:
steps:
- step: &mirror
clone:
enabled: false
name: Mirror to GitHub
script:
- umask 000
- GIT_LFS_SKIP_SMUDGE=1 git clone --mirror https://x-token-auth:$REPOSITORY_OAUTH_ACCESS_TOKEN@bitbucket.org/$BITBUCKET_REPO_FULL_NAME.git repo
- cd repo
- git config user.name bitbucket-pipelines
- git config user.email commits-noreply@bitbucket.org
- git config push.default current
- git config http.${BITBUCKET_GIT_HTTP_ORIGIN}.proxy http://localhost:29418/
- git remote set-url origin http://bitbucket.org/$BITBUCKET_REPO_FULL_NAME
- git reflog expire --expire=all --all
#- echo ".bitbucket/pipelines/generated" >> .git/info/exclude
#- chmod 777 repo
- git push --mirror git@github.com:HoloRes/suisei-bot.git
- step: &lint
name: Code linting
script:
- npm i -g pnpm
- pnpm install
- echo "module.exports = {}" > config.js
- pnpm run lint:ci
caches:
- node
- step: &lintDockerfile
name: Lint the Dockerfile
image: hadolint/hadolint:latest-debian
script:
- hadolint Dockerfile
- step: &build
name: Build
script:
- IMAGE_NAME=$BITBUCKET_REPO_SLUG
- REPO_URL=$BITBUCKET_GIT_HTTP_ORIGIN
- docker build . --file Dockerfile --tag ${IMAGE_NAME}
--label "org.opencontainers.image.url"="${REPO_URL}"
--label "org.opencontainers.image.source"="${REPO_URL}"
--label "org.opencontainers.image.title"="${BITBUCKET_REPO_SLUG}"
--label "org.opencontainers.image.licenses"="MIT"
--label "org.opencontainers.image.description"="A Discord bot specifically built for VTuber servers"
--label "org.opencontainers.image.revision"="${BITBUCKET_COMMIT}"
--label "org.opencontainers.image.version"="${BITBUCKET_BRANCH}"
- docker save ${IMAGE_NAME} --output "${IMAGE_NAME}.tar"
services:
- docker
caches:
- docker
artifacts:
- "*.tar"
- step: &publish
name: Push to GHCR
script:
- IMAGE_NAME=$BITBUCKET_REPO_SLUG
- docker load --input "${IMAGE_NAME}.tar"
- echo ${DOCKER_PASSWORD} | docker login ghcr.io --username "$DOCKER_USERNAME" --password-stdin
- VERSION=$(echo $BITBUCKET_COMMIT | cut -c1-7)
- IMAGE=ghcr.io/${DOCKER_NAMESPACE}/${IMAGE_NAME}
- docker tag "${IMAGE_NAME}" "${IMAGE}:${VERSION}"
- docker push "${IMAGE}:${VERSION}"
services:
- docker
pipelines:
default:
- parallel:
- step: *mirror
- step: *lint
- step: *lintDockerfile
- step: *build
- step: *publish
pull-requests:
main:
- parallel:
- step: *mirror
- step: *lint
- step: *lintDockerfile
- step: *build
- step: *publish
# - step:
# name: Create Sentry release
# script:
# - pipe: holores/sentry-new-release:0.4.0
# variables:
# SENTRY_AUTH_TOKEN: $SENTRY_TOKEN
# SENTRY_ORG: $SENTRY_ORG
# SENTRY_URL: $SENTRY_URL
# SENTRY_PROJECT: $SENTRY_PROJECT
# ENVIRONMENT: "staging"
# services:
# - docker
branches:
main:
- parallel:
- step: *mirror
- step: *lint
- step: *lintDockerfile
- step: *build
- step:
name: Publish docker tag
script:
# Extract package.json version
- export PACKAGE_VERSION=$(node --eval="process.stdout.write(require('./package.json').version)")
# Create and push Docker image
- VERSION=$(echo $BITBUCKET_COMMIT | cut -c1-7)
- echo ${DOCKER_PASSWORD} | docker login ghcr.io --username "$DOCKER_USERNAME" --password-stdin
- IMAGE_NAME=$BITBUCKET_REPO_SLUG
- docker load --input "${IMAGE_NAME}.tar"
- IMAGE=ghcr.io/${DOCKER_NAMESPACE}/${IMAGE_NAME}
- docker tag "${IMAGE_NAME}" "${IMAGE}:${PACKAGE_VERSION}"
- docker tag "${IMAGE_NAME}" "${IMAGE}:${VERSION}"
- docker push "${IMAGE}:${PACKAGE_VERSION}"
- docker push "${IMAGE}:${VERSION}"
services:
- docker
# - step:
# script:
# - VERSION=$(echo $BITBUCKET_COMMIT | cut -c1-7)
# - IMAGE=ghcr.io/${DOCKERHUB_NAMESPACE}/${IMAGE_NAME}
# - pipe: anchore/anchore-scan:0.2.14
# variables:
# IMAGE_NAME: "${IMAGE}:${VERSION}"
# - step:
# name: Create Sentry release
# script:
# - pipe: holores/sentry-new-release:0.4.0
# variables:
# SENTRY_AUTH_TOKEN: $SENTRY_TOKEN
# SENTRY_ORG: $SENTRY_ORG
# SENTRY_URL: $SENTRY_URL
# SENTRY_PROJECT: $SENTRY_PROJECT
# ENVIRONMENT: "production"
- step:
name: Deploy
deployment: production
script:
- VERSION=$(echo $BITBUCKET_COMMIT | cut -c1-7)
- sed -i "s|{{version}}|$VERSION|g" k8s/deployment.yml
- pipe: atlassian/kubectl-run:3.2.0
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: 'apply'
RESOURCE_PATH: 'k8s/deployment.yml'
develop:
- parallel:
- step: *mirror
- step: *lint
- step: *lintDockerfile
- step: *build
- step: *publish
- step:
name: Deploy
deployment: staging
script:
- VERSION=$(echo $BITBUCKET_COMMIT | cut -c1-7)
- sed -i "s|{{version}}|$VERSION|g" k8s/deployment.staging.yml
- pipe: atlassian/kubectl-run:3.2.0
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: 'apply'
RESOURCE_PATH: 'k8s/deployment.staging.yml'