|
| 1 | +#Use the latest 2.1 version of CircleCI pipeline process engine. |
| 2 | +# See: https://circleci.com/docs/configuration-reference |
| 3 | +version: 2.1 |
| 4 | +jobs: |
| 5 | + test: |
| 6 | + machine: |
| 7 | + image: ubuntu-2204:current |
| 8 | + environment: |
| 9 | + DOCKER_SOCKET: /run/docker.sock |
| 10 | + steps: |
| 11 | + - checkout # checkout source code to working directory |
| 12 | + - run: |
| 13 | + name: Run tests |
| 14 | + command: | |
| 15 | + # Open permission on docker.sock to allow containers to spawn other containers |
| 16 | + sudo chmod 777 /run/docker.sock |
| 17 | + # Touching requirements files here so that make doesn't rebuild them - we can't rely on file timestamps in a fresh repo clone |
| 18 | + touch requirements.txt dev-requirements.txt |
| 19 | + make CI=true dev-sync |
| 20 | + docker login -u $DOCKER_CLOUD_USER -p $DOCKER_CLOUD_PASSWORD |
| 21 | + airflow db migrate |
| 22 | + export AIRFLOW_VAR_FLOWAPI_TOKEN="set_in_host" |
| 23 | + export CONTAINER_TAG=$CIRCLE_SHA1 |
| 24 | + export FLOWKIT_VERSION=$(cat .flowkit-version) |
| 25 | + cd tests |
| 26 | + pytest --junitxml=test_out.xml . |
| 27 | + - store_test_results: |
| 28 | + path: tests/test_out.xml |
| 29 | + test_pypi_publish: |
| 30 | + docker: |
| 31 | + - image: cimg/python:3.10 |
| 32 | + steps: |
| 33 | + - checkout # checkout source code to working directory |
| 34 | + - run: |
| 35 | + name: Create and upload wheel to test pypi |
| 36 | + command: | |
| 37 | + pyenv local 3.10 |
| 38 | + python3 setup.py sdist bdist_wheel |
| 39 | + sudo add-apt-repository universe -y |
| 40 | + sudo apt-get update |
| 41 | + sudo apt install -y python3-pip |
| 42 | + sudo pip install pipenv |
| 43 | + pipenv install twine |
| 44 | + pipenv run twine upload --repository testpypi dist/* |
| 45 | +
|
| 46 | + pypi_publish: |
| 47 | + docker: |
| 48 | + - image: cimg/python:3.10 |
| 49 | + steps: |
| 50 | + - checkout # checkout source code to working directory |
| 51 | + - run: |
| 52 | + name: Create and upload wheel to pypi |
| 53 | + command: | |
| 54 | + pyenv local 3.10 |
| 55 | + python3 setup.py sdist bdist_wheel |
| 56 | + sudo add-apt-repository universe -y |
| 57 | + sudo apt-get update |
| 58 | + sudo apt install -y python3-pip |
| 59 | + sudo pip install pipenv |
| 60 | + pipenv install twine |
| 61 | + pipenv run twine upload dist/* |
| 62 | +
|
| 63 | + build_docker_image: |
| 64 | + machine: |
| 65 | + image: ubuntu-2004:2023.10.1 |
| 66 | + working_directory: /home/circleci/project/ |
| 67 | + steps: |
| 68 | + - checkout: |
| 69 | + path: /home/circleci/project/ |
| 70 | + - attach_workspace: |
| 71 | + at: /home/circleci |
| 72 | + - run: sudo apt update && sudo apt install docker-ce |
| 73 | + - run: |
| 74 | + name: Log in to docker cloud |
| 75 | + command: docker login --username $DOCKER_CLOUD_USER --password $DOCKER_CLOUD_PASSWORD |
| 76 | + - run: |
| 77 | + name: Build flowbot image |
| 78 | + command: | |
| 79 | + echo "Tagging as $CIRCLE_SHA1" |
| 80 | + export SOURCE_VERSION=$(git describe --tags --dirty --always | sed s/"-"/"+"/ | sed s/"-"/"."/g) |
| 81 | + DOCKER_BUILDKIT=1 docker build --progress=plain --build-arg FLOWETL_VERSION=$(cat .flowkit-version) --build-arg SOURCE_VERSION=$SOURCE_VERSION -t flowminder/flowbot:$CIRCLE_SHA1 -f Dockerfile . |
| 82 | + - run: |
| 83 | + name: Push images to Docker cloud |
| 84 | + command: | |
| 85 | + docker push flowminder/flowbot:$CIRCLE_SHA1 |
| 86 | +
|
| 87 | + retag_image: |
| 88 | + parameters: |
| 89 | + tag: |
| 90 | + type: string |
| 91 | + default: "latest" |
| 92 | + docker: |
| 93 | + - image: cimg/python:3.7 |
| 94 | + steps: |
| 95 | + - run: |
| 96 | + name: Install retagger |
| 97 | + command: wget -q https://github.com/joshdk/docker-retag/releases/download/0.0.2/docker-retag && sudo install docker-retag /usr/bin |
| 98 | + - run: |
| 99 | + name: Retag |
| 100 | + command: | |
| 101 | + export DOCKER_USER=$DOCKER_CLOUD_USER |
| 102 | + export DOCKER_PASS=$DOCKER_CLOUD_PASSWORD |
| 103 | + docker-retag flowminder/flowbot:$CIRCLE_SHA1 ${<< parameters.tag >>:-latest} |
| 104 | +
|
| 105 | + build_docs: |
| 106 | + docker: |
| 107 | + - image: cimg/python:3.12 |
| 108 | + working_directory: /home/circleci/project/docs |
| 109 | + steps: |
| 110 | + - checkout: |
| 111 | + path: /home/circleci/project/ |
| 112 | + - run: pip install -r requirements.txt |
| 113 | + - run: mkdocs build |
| 114 | + - run: zip -r flowpyter-task-docs.zip flowpyter-task-docs/* |
| 115 | + - store_artifacts: |
| 116 | + path: /home/circleci/project/docs/flowpyter-task-docs.zip |
| 117 | + destination: docs |
| 118 | + |
| 119 | + deploy_docs: |
| 120 | + docker: |
| 121 | + - image: cimg/python:3.12 |
| 122 | + working_directory: /home/circleci/project/docs |
| 123 | + steps: |
| 124 | + - checkout: |
| 125 | + path: /home/circleci/project/ |
| 126 | + - run: pip install -r requirements.txt |
| 127 | + - run: git fetch origin gh-pages --depth=1 |
| 128 | + - run: |
| 129 | + name: Set git committer |
| 130 | + command: | |
| 131 | + git config user.name $GIT_COMMITTER_NAME |
| 132 | + git config user.email $GIT_COMMITTER_EMAIL |
| 133 | + - run: mike deploy --push --update-aliases ${CIRCLE_TAG:="main"} latest |
| 134 | + |
| 135 | +workflows: |
| 136 | + test_publish: |
| 137 | + jobs: |
| 138 | + - test: |
| 139 | + context: org-global |
| 140 | + filters: |
| 141 | + tags: |
| 142 | + only: /.*/ |
| 143 | + requires: |
| 144 | + - build_docker_image |
| 145 | + - build_docs: |
| 146 | + context: org-global |
| 147 | + filters: |
| 148 | + tags: |
| 149 | + only: /.*/ |
| 150 | + - deploy_docs: |
| 151 | + context: org-global |
| 152 | + filters: |
| 153 | + branches: |
| 154 | + only: |
| 155 | + - main |
| 156 | + tags: |
| 157 | + only: /.*/ |
| 158 | + requires: |
| 159 | + - build_docs |
| 160 | + - test |
| 161 | + - build_docker_image |
| 162 | + - test_pypi_publish: |
| 163 | + requires: |
| 164 | + - test |
| 165 | + context: test-pypi |
| 166 | + filters: |
| 167 | + branches: |
| 168 | + only: |
| 169 | + - test_upload |
| 170 | + - pypi_publish: |
| 171 | + requires: |
| 172 | + - test |
| 173 | + context: org-global |
| 174 | + filters: |
| 175 | + branches: |
| 176 | + only: |
| 177 | + - main |
| 178 | + tags: |
| 179 | + only: /.*/ |
| 180 | + - build_docker_image: |
| 181 | + context: org-global |
| 182 | + filters: |
| 183 | + tags: |
| 184 | + only: /.*/ |
| 185 | + - retag_image: |
| 186 | + name: retag_master_branch |
| 187 | + requires: &retag_requirements |
| 188 | + - test |
| 189 | + - build_docker_image |
| 190 | + context: org-global |
| 191 | + filters: |
| 192 | + branches: |
| 193 | + only: |
| 194 | + - main |
| 195 | + tags: |
| 196 | + only: /.*/ |
0 commit comments