|
1 | 1 | version: 2.1 |
| 2 | +orbs: |
| 3 | + aws-cli: circleci/aws-cli@5.4.1 |
| 4 | + slack: circleci/slack@6.1.3 |
| 5 | + |
| 6 | +executors: |
| 7 | + node: |
| 8 | + docker: |
| 9 | + - image: python:latest |
| 10 | + |
2 | 11 | references: |
3 | 12 | workspace_root: &workspace_root ~/workspace |
4 | 13 |
|
@@ -49,19 +58,55 @@ jobs: |
49 | 58 | #- run: uv run pytest -v Needs /etc/hypercorn.toml |
50 | 59 | - run: |
51 | 60 | name: Build docker image |
52 | | - command: docker build -t khteh/pythonrestapi:latest . |
| 61 | + command: | |
| 62 | + VERSION=$(uv run python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])").$CIRCLE_BUILD_NUM |
| 63 | + docker build -t khteh/pythonrestapi:latest -t khteh/pythonrestapi:$VERSION . |
53 | 64 | - run: |
54 | 65 | name: Login to docker hub |
55 | 66 | command: docker login -u $DOCKER_USER -p $DOCKER_PASS |
56 | 67 | - run: |
57 | 68 | name: Push images to docker hub |
58 | | - command: docker push khteh/pythonrestapi:latest |
| 69 | + command: | |
| 70 | + VERSION=$(uv run python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])").$CIRCLE_BUILD_NUM |
| 71 | + echo ${VERSION} > docker-build_number.txt |
| 72 | + docker push khteh/pythonrestapi:latest |
| 73 | + docker push khteh/pythonrestapi:$VERSION |
59 | 74 | - save_cache: |
60 | 75 | key: v1-dependencies-{{ .Branch }}-{{ checksum "uv.lock" }} |
61 | 76 | paths: |
62 | 77 | - /home/circleci/.local/bin |
63 | 78 | - /home/circleci/.local/lib |
| 79 | + - persist_to_workspace: |
| 80 | + root: *workspace_root |
| 81 | + paths: |
| 82 | + - . |
| 83 | + deploy-eks: |
| 84 | + executor: aws-cli/default |
| 85 | + <<: *defaults |
| 86 | + steps: |
| 87 | + - *attach_workspace |
| 88 | + - setup_remote_docker: |
| 89 | + docker_layer_caching: true |
| 90 | + - aws-cli/setup: |
| 91 | + profile-name: default |
| 92 | + - run: |
| 93 | + name: Use the saved build number here |
| 94 | + command: | |
| 95 | + echo 'export CIRCLE_BUILD_NUM_DOCKER="$(cat docker-build_number.txt)"' >> $BASH_ENV |
| 96 | + . $BASH_ENV |
| 97 | + echo CIRCLE_BUILD_NUM_DOCKER: $CIRCLE_BUILD_NUM_DOCKER |
| 98 | + - run: |
| 99 | + name: Update Python RestAPI application |
| 100 | + command: | |
| 101 | + #kubectl patch statefulset pythonrestapi --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"'$AWS_ACCOUNT_ID'.dkr.ecr.ap-southeast-1.amazonaws.com/pythonrestapi:'$CIRCLE_BUILD_NUM_DOCKER'"}]' |
| 102 | + kubectl set image sts/pythonrestapi pythonrestapi=$AWS_ACCOUNT_ID.dkr.ecr.ap-southeast-1.amazonaws.com/pythonrestapi:$CIRCLE_BUILD_NUM_DOCKER |
64 | 103 | workflows: |
65 | 104 | main: |
66 | 105 | jobs: |
67 | 106 | - build_and_test |
| 107 | +# - deploy-eks: |
| 108 | +# requires: |
| 109 | +# - build |
| 110 | +# filters: |
| 111 | +# branches: |
| 112 | +# only: master |
0 commit comments