-
Notifications
You must be signed in to change notification settings - Fork 1.4k
154 lines (132 loc) · 5.46 KB
/
customer-data-pipeline.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#
# Build and test the Docker image for the CDP service found in the cdp/
# directory.
#
# This job is triggered by pushes to the master branch and by pull requests that
# touch the cdp/ directory.
#
# Once built we run the functional tests against the running image.
name: CDP CI
on:
push:
branches:
- master
paths:
- cdp/**
- .github/workflows/customer-data-pipeline.yml
pull_request:
branches:
- master
paths:
- cdp/**
- .github/workflows/customer-data-pipeline.yml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Lowercase GITHUB_REPOSITORY
id: lowercase
run: |
echo "repository=${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- uses: docker/metadata-action@v4
id: meta
with:
images: ghcr.io/${{ steps.lowercase.outputs.repository }}/cdp
# Make the image tags used for docker cache. We use this rather than
# ${{ github.repository }} directly because the repository
# organization name is has upper case characters, which are not
# allowed in docker image names.
- uses: docker/metadata-action@v4
id: meta-cache
with:
images: ghcr.io/${{ steps.lowercase.outputs.repository }}/cdp
tags: |
type=raw,value=cache
- uses: docker/build-push-action@v4
with:
context: cdp
file: cdp/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ steps.meta-cache.outputs.tags }}
cache-to: type=registry,ref=${{ steps.meta-cache.outputs.tags }},mode=max
# Output the image tags so that we can use them in the next job.
outputs:
tags: ${{ steps.meta.outputs.tags }}
test:
# Run the functional tests against the CDP service. We pull the image
# from GHCR and run it locally. We need only the db service from the
# main docker-compose.yml file, so we use the --services flag to only
# start that service.
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8.x.x
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'pnpm'
cache-dependency-path: cdp/pnpm-lock.yaml
- name: Install test dependencies
working-directory: cdp
run: |
pnpm install --frozen-lockfile
- name: Start CDP
working-directory: cdp
run: |
mkdir -p /tmp/logs
docker compose -f ../docker-compose.dev.yml up -d db >> /tmp/logs/db.txt
# Wait for the db service to be ready, up to 30 seconds.
SECONDS=0
until docker compose -f ../docker-compose.dev.yml exec -T db pg_isready; do
if [ $SECONDS -gt 30 ]; then
echo "Timed out waiting for db service to be ready."
exit 1
fi
sleep 1
done
# Create a shell alias for the docker image we just built, using the tags output.
export SECRET_KEY=$(openssl rand -hex 32)
CDP_RUN="docker run -e SECRET_KEY=$SECRET_KEY -e DATABASE_URL=postgres://posthog:posthog@localhost:5432/posthog --rm --network=host ${{ needs.build.outputs.tags }}"
# Run the migrations.
$CDP_RUN sqlx migrate run
# Start the CDP service.
$CDP_RUN &> /tmp/logs/cdp.txt &
# Run the functional tests.
pnpm jest
- name: Lowercase GITHUB_REPOSITORY
id: lowercase
run: |
echo "repository=${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- name: Generate docker latest tag
if: github.ref == 'refs/heads/master'
uses: docker/metadata-action@v4
id: meta
with:
images: ghcr.io/${{ steps.lowercase.outputs.repository }}/cdp
tags: |
type=raw,value=latest
- name: Push image as latest on master
if: github.ref == 'refs/heads/master'
run: |
docker tag ${{ needs.build.outputs.tags }} ${{ steps.meta.outputs.tags }}
docker push ${{ steps.meta.outputs.tags }}