-
Notifications
You must be signed in to change notification settings - Fork 1
136 lines (131 loc) · 4.74 KB
/
ci.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
name: CI
on:
push:
branches:
- develop
pull_request:
branches:
- develop
env:
HASH_SEEDS: pdm.lock docker/bin/* docker/conf/* docker/Dockerfile
DOCKER_CACHE_IMAGE: ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images
BUILD_DATE: $(date +"%Y-%m-%d %H:%M")
DOCKER_DEFAULT_PLATFORM: linux/amd64
jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: DockerHub login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Check Dev Image
continue-on-error: true
id: image_exists
run: |
set +e
LOCK_SHA=$(echo sha1sum ${{env.HASH_SEEDS}}| sha1sum | awk '{print $1}' | cut -c 1-8)
exists=$(docker manifest inspect ${DOCKER_CACHE_IMAGE}:hde-dev-${LOCK_SHA} > /dev/null 2>&1 && echo "exists" || echo "not_found")
exists="exists"
echo "result=$exists" >> "$GITHUB_OUTPUT"
echo "SHA=$LOCK_SHA" >> "$GITHUB_OUTPUT"
if [ $exists = "exists" ];then
echo "Tag ${{ steps.image_exists.outputs.SHA }} found"
else
echo "Tag ${{ steps.image_exists.outputs.SHA }} does not exist"
fi
- name: Build Dev Image
if: ${{ steps.image_exists.outputs.result == 'not_found' || contains(github.event.head_commit.message, 'rebuild') }}
run: |
LOCK_SHA=${{ steps.image_exists.outputs.SHA }}
docker buildx create --use --platform x86_64 --name builder --driver docker-container
docker buildx build \
--platform x86_64 \
--builder builder \
--build-arg BUILD_DATE="${BUILD_DATE}" \
--progress=plain \
--cache-to type=local,ref=${DOCKER_CACHE_IMAGE}:hde-dev-latest,dest=./.AAA \
--cache-from ${DOCKER_CACHE_IMAGE}:hde-dev-latest \
-t ${DOCKER_CACHE_IMAGE}:hde-dev-${LOCK_SHA} \
-t ${DOCKER_CACHE_IMAGE}:hde-dev-latest \
-f ./docker/Dockerfile \
--push \
--target python_dev_deps .
lint:
runs-on: ubuntu-20.04
needs: [build]
container:
image: unicef/hope-support-images:hde-dev-latest
credentials:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Black
run: black --check src/
- name: Flake8
run: flake8 src/
test:
runs-on: ubuntu-20.04
needs: [build]
container:
image: unicef/hope-support-images:hde-dev-latest
credentials:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
ports:
- 8000:8000
services:
redis:
image: redis
db:
image: postgres:14
env:
POSTGRES_DATABASE: dedupe
POSTGRES_PASSWORD: postgres
POSTGRES_USERNAME: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/dedupe
SECRET_KEY: secret_key
CACHE_URL: redis://redis:6379/0
CELERY_BROKER_URL: redis://redis:6379/0
PYTHONPATH: "/hde/code/src:/hde/__pypackages__/3.12/lib"
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
run: |
pytest tests
# echo "==================================="
# ls -al
# docker run --rm \
# -e PYTHONPATH=/hde/code/src:/hde/__pypackages__/3.12/lib \
# -e CACHE_URL="${CACHE_URL}" \
# -e DATABASE_URL="${DATABASE_URL}" \
# -e SECRET_KEY="${SECRET_KEY}" \
# -e CELERY_BROKER_URL="${CELERY_BROKER_URL}" \
# -v ${PWD}:/hde/code/ \
# -w /hde/code/ \
# -t ${DOCKER_CACHE_IMAGE}:hde-dev-latest \
# pytest tests/ --create-db -v --cov --cov-report xml:coverage.xml
#
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v4
# with:
# directory: ./coverage/reports/
# env_vars: OS,PYTHON
# fail_ci_if_error: true
# files: /hde/code/coverage1.xml
# flags: unittests
# name: codecov-umbrella
# token: ${{ secrets.CODECOV_TOKEN }}
# verbose: true