395 строки
12 KiB
YAML
395 строки
12 KiB
YAML
# These environment variables must be set in CircleCI UI
|
|
#
|
|
# DOCKERHUB_REPO - docker hub repo, format: <username>/<repo>
|
|
# DOCKER_USER - Login user for docker hub
|
|
# DOCKER_PASS - Login password for docker hub user
|
|
# NPM_TOKEN - A valid NPM token for releases
|
|
version: 2.1
|
|
|
|
orbs:
|
|
codecov: codecov/codecov@3.2.4
|
|
|
|
references:
|
|
defaults: &defaults
|
|
working_directory: ~/addons-frontend
|
|
docker:
|
|
# This is the NodeJS version we run in production.
|
|
- image: cimg/node:18.20
|
|
|
|
defaults-next: &defaults-next
|
|
working_directory: ~/addons-frontend
|
|
docker:
|
|
# This is the next NodeJS version we will support.
|
|
- image: cimg/node:20.12
|
|
|
|
defaults-release: &defaults-release
|
|
machine:
|
|
image: ubuntu-2004:current
|
|
working_directory: ~/addons-frontend
|
|
|
|
restore_build_cache: &restore_build_cache
|
|
restore_cache:
|
|
name: restore yarn package cache
|
|
keys:
|
|
- yarn-packages-v16-{{ checksum "yarn.lock" }}
|
|
|
|
run_yarn_install: &run_yarn_install
|
|
run:
|
|
name: install dependencies
|
|
# See: https://github.com/mozilla/addons-frontend/issues/3034
|
|
command: yarn install --pure-lockfile
|
|
|
|
save_build_cache: &save_build_cache
|
|
save_cache:
|
|
name: save yarn package cache
|
|
key: yarn-packages-v16-{{ checksum "yarn.lock" }}
|
|
paths:
|
|
- ~/.cache/yarn
|
|
|
|
restore_next_build_cache: &restore_next_build_cache
|
|
restore_cache:
|
|
name: restore yarn package cache
|
|
keys:
|
|
- next-yarn-packages-v18-{{ checksum "yarn.lock" }}
|
|
|
|
save_next_build_cache: &save_next_build_cache
|
|
save_cache:
|
|
name: save yarn package cache
|
|
key: next-yarn-packages-v18-{{ checksum "yarn.lock" }}
|
|
paths:
|
|
- ~/.cache/yarn
|
|
|
|
commands:
|
|
better_checkout:
|
|
description: circle ci checkout step on steroids
|
|
parameters:
|
|
clone_options:
|
|
type: string
|
|
default: --depth=1
|
|
description: git clone options
|
|
fetch_options:
|
|
type: string
|
|
default: --depth=10
|
|
description: git fetch options
|
|
steps:
|
|
- run:
|
|
name: checkout
|
|
command: |
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
# Workaround old docker images with incorrect $HOME
|
|
# check https://github.com/docker/docker/issues/2968 for details
|
|
if [ "${HOME}" = "/" ]
|
|
then
|
|
export HOME=$(getent passwd $(id -un) | cut -d: -f6)
|
|
fi
|
|
|
|
export SSH_CONFIG_DIR="$HOME/.ssh"
|
|
|
|
echo "Using SSH Config Dir $SSH_CONFIG_DIR"
|
|
|
|
mkdir -p "$SSH_CONFIG_DIR"
|
|
|
|
echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=' >> "$SSH_CONFIG_DIR/known_hosts"
|
|
|
|
(umask 077; touch "$SSH_CONFIG_DIR/id_rsa")
|
|
chmod 0600 "$SSH_CONFIG_DIR/id_rsa"
|
|
(cat $CHECKOUT_KEY > "$SSH_CONFIG_DIR/id_rsa")
|
|
|
|
export GIT_SSH_COMMAND='ssh -i $SSH_CONFIG_DIR/id_rsa -o UserKnownHostsFile=$SSH_CONFIG_DIR/known_hosts'
|
|
|
|
# use git+ssh instead of https
|
|
git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true
|
|
git config --global gc.auto 0 || true
|
|
|
|
if [ -e .git ]
|
|
then
|
|
git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true
|
|
else
|
|
git clone << parameters.clone_options >> "$CIRCLE_REPOSITORY_URL" .
|
|
fi
|
|
|
|
if [ -n "$CIRCLE_TAG" ]
|
|
then
|
|
git fetch << parameters.fetch_options >> --force origin "refs/tags/${CIRCLE_TAG}"
|
|
elif [[ "$CIRCLE_BRANCH" =~ ^pull\/* ]]
|
|
then
|
|
git fetch << parameters.fetch_options >> --force origin "${CIRCLE_BRANCH}/head:remotes/origin/${CIRCLE_BRANCH}"
|
|
else
|
|
git fetch << parameters.fetch_options >> --force origin "${CIRCLE_BRANCH}:remotes/origin/${CIRCLE_BRANCH}"
|
|
fi
|
|
|
|
|
|
if [ -n "$CIRCLE_TAG" ]
|
|
then
|
|
git reset --hard "$CIRCLE_SHA1"
|
|
git checkout -q "$CIRCLE_TAG"
|
|
elif [ -n "$CIRCLE_BRANCH" ]
|
|
then
|
|
git reset --hard "$CIRCLE_SHA1"
|
|
git checkout -q -B "$CIRCLE_BRANCH"
|
|
fi
|
|
|
|
git reset --hard "$CIRCLE_SHA1"
|
|
|
|
jobs:
|
|
build:
|
|
<<: *defaults
|
|
steps:
|
|
- checkout
|
|
- *restore_build_cache
|
|
- *run_yarn_install
|
|
- *save_build_cache
|
|
- run: yarn build-ci
|
|
|
|
build-docker-image:
|
|
<<: *defaults-release
|
|
steps:
|
|
- checkout
|
|
- run:
|
|
name: Build the docker image
|
|
command: docker build --pull .
|
|
|
|
build-blog-utils:
|
|
<<: *defaults
|
|
steps:
|
|
- checkout
|
|
- *restore_build_cache
|
|
- *run_yarn_install
|
|
- *save_build_cache
|
|
- run: yarn build:blog-utils-prod
|
|
# Set up a workspace to share data between this job and the
|
|
# `release-blog-utils` one when we want to publish a new npm version.
|
|
- persist_to_workspace:
|
|
root: ~/addons-frontend
|
|
paths: dist
|
|
|
|
|
|
test:
|
|
<<: *defaults
|
|
steps:
|
|
- better_checkout
|
|
- *restore_build_cache
|
|
- *run_yarn_install
|
|
- *save_build_cache
|
|
- run: yarn test-ci
|
|
- codecov/upload
|
|
|
|
check:
|
|
<<: *defaults
|
|
docker:
|
|
- image: cimg/python:3.11-node
|
|
steps:
|
|
- better_checkout
|
|
- *restore_build_cache
|
|
- *run_yarn_install
|
|
- *save_build_cache
|
|
- run: yarn lint
|
|
- run: yarn prettier-ci
|
|
- run: pip install 'fonttools<4.44.1' brotli && yarn check-fonts
|
|
|
|
build-next:
|
|
<<: *defaults-next
|
|
steps:
|
|
- checkout
|
|
- *restore_next_build_cache
|
|
- *run_yarn_install
|
|
- *save_next_build_cache
|
|
- run: yarn build
|
|
|
|
test-next:
|
|
<<: *defaults-next
|
|
steps:
|
|
- better_checkout
|
|
- *restore_next_build_cache
|
|
- *run_yarn_install
|
|
- *save_next_build_cache
|
|
- run: yarn test-ci-next
|
|
|
|
dennis-lint:
|
|
<<: *defaults-release
|
|
steps:
|
|
- better_checkout
|
|
- run: pip install tox
|
|
- run: TOXENV=dennis-lint tox
|
|
|
|
|
|
release-blog-utils:
|
|
<<: *defaults
|
|
steps:
|
|
- attach_workspace:
|
|
at: ~/addons-frontend
|
|
- run:
|
|
name: authenticate with registry
|
|
# We don't want to expand the token in this file, npm will do it.
|
|
command: echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > ~/addons-frontend/dist/.npmrc
|
|
- run:
|
|
name: publish package
|
|
command: cd dist && npm publish
|
|
|
|
release-tag: # build for the tags
|
|
<<: *defaults-release
|
|
steps:
|
|
- checkout
|
|
- run:
|
|
name: Install dependencies
|
|
command: sudo apt-get update; sudo apt-get install pigz
|
|
- run:
|
|
name: "Install Tox"
|
|
command: pip install tox
|
|
- run: docker info
|
|
# Build the container, using Circle's Docker cache. Only use 1 image per
|
|
# day to keep the cache size down.
|
|
- run:
|
|
name: Build the container ( Next 3 steps )
|
|
command: IMG="image-$(date +%j).gz"; if [[ -e ~/addons-frontend/docker/$IMG ]]; then echo "Loading $IMG"; pigz -d -c ~/addons-frontend/docker/$IMG | docker load; fi
|
|
- run: >
|
|
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n'
|
|
"$CIRCLE_SHA1"
|
|
"$CIRCLE_TAG"
|
|
"$CIRCLE_PROJECT_USERNAME"
|
|
"$CIRCLE_PROJECT_REPONAME"
|
|
"$CIRCLE_BUILD_URL"
|
|
> version.json
|
|
- run:
|
|
name: Build the docker image
|
|
command: |
|
|
docker login -u $DOCKER_USER -p $DOCKER_PASS
|
|
docker build --pull -t addons-frontend .
|
|
- run: docker images
|
|
- run:
|
|
name: Build the app and check bundlesize from container
|
|
command: |
|
|
docker run --rm addons-frontend yarn build-ci
|
|
- run:
|
|
name: Write the sha256 sum to an artifact for verification
|
|
command: |
|
|
docker images --no-trunc | awk '/^app/ {print $3}' | sudo tee $CIRCLE_ARTIFACTS/docker-image-shasum256.txt
|
|
- run:
|
|
name: Save new image
|
|
command: |
|
|
IMG="image-$(date +%j).gz"; docker save addons-frontend | pigz --fast -c > ~/addons-frontend/docker/$IMG; ls -l ~/addons-frontend/docker
|
|
ls -l ~/addons-frontend/docker
|
|
- run:
|
|
name: Push to repo
|
|
command: |
|
|
[ ! -z $DOCKERHUB_REPO ]
|
|
echo $DOCKERHUB_REPO:$CIRCLE_TAG
|
|
docker tag addons-frontend $DOCKERHUB_REPO:$CIRCLE_TAG
|
|
docker images
|
|
docker push $DOCKERHUB_REPO:$CIRCLE_TAG
|
|
- run:
|
|
name: Set hosts
|
|
command: |
|
|
echo 127.0.0.1 olympia.test | sudo tee -a /etc/hosts
|
|
cat /etc/hosts
|
|
- run:
|
|
name: Test Image
|
|
command: |
|
|
sudo sysctl -w vm.max_map_count=262144
|
|
./tests/smoke/setup_docker.sh
|
|
tox -e smoke-tests
|
|
|
|
release-master: # build for the master branch
|
|
<<: *defaults-release
|
|
steps:
|
|
- checkout
|
|
- run:
|
|
name: Install dependencies
|
|
command: sudo apt-get update; sudo apt-get install pigz
|
|
- run:
|
|
name: "Install Tox"
|
|
command: pip install tox
|
|
- run: docker info
|
|
# Build the container, using Circle's Docker cache. Only use 1 image per
|
|
# day to keep the cache size down.
|
|
- run:
|
|
name: Build the container ( Next 2 steps )
|
|
command: IMG="image-$(date +%j).gz"; if [[ -e ~/addons-frontend/docker/$IMG ]]; then echo "Loading $IMG"; pigz -d -c ~/addons-frontend/docker/$IMG | docker load; fi
|
|
- run: >
|
|
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n'
|
|
"$CIRCLE_SHA1"
|
|
"$CIRCLE_TAG"
|
|
"$CIRCLE_PROJECT_USERNAME"
|
|
"$CIRCLE_PROJECT_REPONAME"
|
|
"$CIRCLE_BUILD_URL"
|
|
> version.json
|
|
- run:
|
|
name: Build the docker image
|
|
command: |
|
|
docker login -u $DOCKER_USER -p $DOCKER_PASS
|
|
docker build --pull -t addons-frontend .
|
|
- run: docker images
|
|
- run:
|
|
name: Build the app and check bundlesize from container
|
|
command: |
|
|
docker run --rm addons-frontend yarn build-ci
|
|
- run:
|
|
name: Write the sha256 sum to an artifact for verification
|
|
command: |
|
|
docker images --no-trunc | awk '/^app/ {print $3}' | sudo tee $CIRCLE_ARTIFACTS/docker-image-shasum256.txt
|
|
- run:
|
|
name: Save new image
|
|
command: |
|
|
IMG="image-$(date +%j).gz"; docker save addons-frontend | pigz --fast -c > ~/addons-frontend/docker/$IMG; ls -l ~/addons-frontend/docker
|
|
ls -l ~/addons-frontend/docker
|
|
- run:
|
|
name: Push to repo
|
|
command: |
|
|
[ ! -z $DOCKERHUB_REPO ]
|
|
docker tag addons-frontend $DOCKERHUB_REPO:latest
|
|
docker push $DOCKERHUB_REPO:latest
|
|
- run:
|
|
name: Set hosts
|
|
command: |
|
|
echo 127.0.0.1 olympia.test | sudo tee -a /etc/hosts
|
|
cat /etc/hosts
|
|
- run:
|
|
name: Test Image
|
|
command: |
|
|
sudo sysctl -w vm.max_map_count=262144
|
|
./tests/smoke/setup_docker.sh
|
|
tox -e smoke-tests
|
|
|
|
workflows:
|
|
version: 2
|
|
default-workflow:
|
|
jobs:
|
|
- build
|
|
- build-docker-image:
|
|
filters:
|
|
branches:
|
|
ignore: master
|
|
tags:
|
|
ignore: /.*/
|
|
- test
|
|
- build-next
|
|
- test-next
|
|
- check
|
|
- dennis-lint
|
|
- build-blog-utils:
|
|
filters: # required since `release-blog-utils` has tag filters AND requires this job
|
|
tags:
|
|
only: /^blog-utils-.*/
|
|
- release-tag:
|
|
filters:
|
|
tags:
|
|
only: /^\d+.*/
|
|
branches:
|
|
ignore: /.*/
|
|
- release-blog-utils:
|
|
filters:
|
|
tags:
|
|
only: /^blog-utils-.*/
|
|
branches:
|
|
ignore: /.*/
|
|
requires:
|
|
- build-blog-utils
|
|
- release-master:
|
|
filters:
|
|
branches:
|
|
only: master
|
|
tags:
|
|
ignore: /.*/
|