Last active
October 6, 2022 09:42
-
-
Save syossan27/920af6b819841a11bdbca6d2c90563e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
build: | |
docker: | |
- image: circleci/node:14 | |
steps: | |
- checkout | |
- setup_remote_docker: | |
version: 20.10.14 | |
docker_layer_caching: true | |
- run: | |
name: google authentication | |
command: | | |
echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=- | |
gcloud auth configure-docker --quiet | |
- run: | |
name: Setup Rollbar code version | |
command: | | |
# CIRCLE_SHA1をSouceMap・Clientの両方のcode_versionとする | |
echo 'export ROLLBAR_CODE_VERSION="$CIRCLE_SHA1"' >> "$BASH_ENV" | |
- run: | |
name: yarn install | |
command: | | |
yarn install | |
- run: | |
name: Build NextJS | |
command: | | |
next build --no-lint | |
- run: | |
name: Upload SourceMap to Rollbar | |
command: | | |
# 本番以外は使わないので弾くようにする | |
if [ ${DEPLOY_ENV} != production ]; then | |
exit 0 | |
fi | |
# SourceMapのminified_urlを設定するために、 | |
# yqを使ってconfigのyamlからアプリケーション毎に記述しているプロトコル+ホスト名を取得してくる | |
curl -LJO https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 | |
sudo mv yq_linux_amd64 /usr/local/bin/yq | |
sudo chmod a+x /usr/local/bin/yq | |
export APP_HOST=`yq .APP_HOST config/${DEPLOY_ENV}.yml` | |
# js, cssにあるSourceMapを一つずつAPIを使ってアップロードする | |
for path in $(find .next -name "*.js" -or -name "*.css"); do | |
if [ -e "$path.map" ]; then | |
# 実際のURLはhttps://example.com/_next/static/~~~のような形式になるため、 | |
# .next -> _nextに置換する | |
file=${path/.next/_next} | |
url=${APP_HOST}/$file | |
source_map="@$path.map" | |
curl --silent --show-error https://api.rollbar.com/api/1/sourcemap \ | |
-F access_token=${ROLLBAR_SERVER_TOKEN} \ | |
-F version=${CIRCLE_SHA1} \ | |
-F minified_url=$url \ | |
-F source_map=$source_map \ | |
> /dev/null | |
fi | |
done | |
# 本番環境にSourceMapを置きたくないので事前に削除 | |
rm -rf .next/**/*.map | |
- run: | |
name: Build app image | |
command: | | |
# よしなにDockerビルド | |
docker build | |
- run: | |
name: Push app image | |
command: | | |
# よしなにDockerプッシュ | |
docker push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment