-
Notifications
You must be signed in to change notification settings - Fork 16
487 lines (386 loc) · 15.6 KB
/
buildimage.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
name: Build Draft Release
on:
push:
tags:
- 'v*'
env:
PROJECT_ID: steampipe
IMAGE_NAME: fdw
CORE_REPO: us-docker.pkg.dev/steampipe/steampipe
ORG: turbot
CONFIG_SCHEMA_VERSION: "2020-11-18"
VERSION: ${{ github.event.ref }}
jobs:
build-osx:
name: Build for Darwin x86_64
runs-on: macos-13
steps:
- name: Install PostgreSQL@14
run: brew install --force postgresql@14
- name: PGConfig
run: |-
which pg_config
ls -l $(which pg_config)
PGXS=$(pg_config --pgxs)
SERVER_LIB=$(pg_config --includedir)/server
INTERNAL_LIB=$(pg_config --includedir)/internal
echo $PGXS
echo $SERVER_LIB
echo $INTERNAL_LIB
ls -l $PGXS
ls -l $SERVER_LIB
ls -l $INTERNAL_LIB
- name: Checkout
uses: actions/checkout@v4
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: 1.21
- name: Fetching Go Cache Paths
id: go-cache-paths
run: |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: Go Build Cache
id: build-cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- name: Go Mod Cache
id: mod-cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: make clean
run: |-
go version
which pg_config
pg_config --version
export PATH=$(pg_config --bindir):$PATH
export PGXS=$(pg_config --pgxs)
export SERVER_LIB=$(pg_config --includedir)/server
export INTERNAL_LIB=$(pg_config --includedir)/internal
export CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
export PG_CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
export LDFLAGS=$(pg_config --ldfalgs)
export PG_LDFLAGS=$(pg_config --ldfalgs)
make clean
- name: make
run: |-
go version
which pg_config
pg_config --version
export PATH=$(pg_config --bindir):$PATH
export PGXS=$(pg_config --pgxs)
export SERVER_LIB=$(pg_config --includedir)/server
export INTERNAL_LIB=$(pg_config --includedir)/internal
export CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
export PG_CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
export LDFLAGS=$(pg_config --ldfalgs)
export PG_LDFLAGS=$(pg_config --ldfalgs)
make
- name: gzip the steampipe_postgres_fdw.so
run: |-
gzip build-Darwin/steampipe_postgres_fdw.so
mv build-Darwin/steampipe_postgres_fdw.so.gz build-Darwin/steampipe_postgres_fdw.so.darwin_amd64.gz
- name: Save MacOS Build Artifact - AMD64
uses: actions/upload-artifact@v4
with:
name: steampipe_postgres_fdw.so.darwin_amd64
path: build-Darwin/steampipe_postgres_fdw.so.darwin_amd64.gz
if-no-files-found: error
- name: Save steampipe_postgres_fdw.control # only need this once for ALL platforms
uses: actions/upload-artifact@v4
with:
name: steampipe_postgres_fdw.control
path: ./fdw/steampipe_postgres_fdw.control
if-no-files-found: error
- name: Save steampipe_postgres_fdw--1.0.sql # only need this once for ALL platforms
uses: actions/upload-artifact@v4
with:
name: steampipe_postgres_fdw--1.0.sql
path: ./fdw/steampipe_postgres_fdw--1.0.sql
if-no-files-found: error
build-osx-arm:
name: Build for Darwin ARM64
runs-on: macos-latest
steps:
- name: Install PostgreSQL@14
run: brew install --force postgresql@14
- name: PGConfig
run: |-
which pg_config
ls -l $(which pg_config)
PGXS=$(pg_config --pgxs)
SERVER_LIB=$(pg_config --includedir)/server
INTERNAL_LIB=$(pg_config --includedir)/internal
echo $PGXS
echo $SERVER_LIB
echo $INTERNAL_LIB
ls -l $PGXS
ls -l $SERVER_LIB
ls -l $INTERNAL_LIB
- name: Checkout
uses: actions/checkout@v4
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: 1.21
- name: Fetching Go Cache Paths
id: go-cache-paths
run: |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: Go Build Cache
id: build-cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- name: Go Mod Cache
id: mod-cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: make clean
run: |-
go version
which pg_config
pg_config --version
export PATH=$(pg_config --bindir):$PATH
export PGXS=$(pg_config --pgxs)
export SERVER_LIB=$(pg_config --includedir)/server
export INTERNAL_LIB=$(pg_config --includedir)/internal
export CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
export PG_CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
export LDFLAGS=$(pg_config --ldfalgs)
export PG_LDFLAGS=$(pg_config --ldfalgs)
make clean
- name: make
run: |-
go version
which pg_config
pg_config --version
export PATH=$(pg_config --bindir):$PATH
export PGXS=$(pg_config --pgxs)
export SERVER_LIB=$(pg_config --includedir)/server
export INTERNAL_LIB=$(pg_config --includedir)/internal
export CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
export PG_CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
export LDFLAGS=$(pg_config --ldfalgs)
export PG_LDFLAGS=$(pg_config --ldfalgs)
make
- name: gzip the steampipe_postgres_fdw.so
run: |-
gzip build-Darwin/steampipe_postgres_fdw.so
mv build-Darwin/steampipe_postgres_fdw.so.gz build-Darwin/steampipe_postgres_fdw.so.darwin_arm64.gz
- name: Save MacOS Build Artifact - AMD64
uses: actions/upload-artifact@v4
with:
name: steampipe_postgres_fdw.so.darwin_arm64
path: build-Darwin/steampipe_postgres_fdw.so.darwin_arm64.gz
if-no-files-found: error
build-linux:
name: Build for Linux x86_64
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup GoLang
uses: actions/setup-go@v5
with:
go-version: 1.21
- name: Fetching Go Cache Paths
id: go-cache-paths
run: |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: Go Build Cache
id: build-cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- name: Go Mod Cache
id: mod-cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Setup apt-get
run: |-
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo env ACCEPT_EULA=Y apt-get update
sudo env ACCEPT_EULA=Y apt-get upgrade
- name: Install PostgreSQL14 Dev
run: |-
sudo apt-get -y install postgresql-server-dev-14
- name: Find stuff and set env
run: |-
which pg_config
pg_config --version
export PATH=$(pg_config --bindir):$PATH
export PGXS=$(pg_config --pgxs)
export SERVER_LIB=$(pg_config --includedir)/14/server
export INTERNAL_LIB=$(pg_config --includedir)/internal
export CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
export PG_CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
export LDFLAGS=$(pg_config --ldflags)
export PG_LDFLAGS=$(pg_config --ldflags)
ls -la $SERVER_LIB
ls -la $INTERNAL_LIB
- name: make clean
run: |-
go version
make clean
- name: make
run: |-
make
- name: gzip the steampipe_postgres_fdw.so
run: |-
gzip build-Linux/steampipe_postgres_fdw.so
mv build-Linux/steampipe_postgres_fdw.so.gz build-Linux/steampipe_postgres_fdw.so.linux_amd64.gz
- name: Save Linux Build Artifact - AMD64
uses: actions/upload-artifact@v4
with:
name: steampipe_postgres_fdw.so.linux_amd64
path: build-Linux/steampipe_postgres_fdw.so.linux_amd64.gz
if-no-files-found: error
build-linux-arm:
name: Build for Linux ARM64 (on AWS EC2)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials
run: |
mkdir ~/.aws
echo -e "[default]\naws_access_key_id = ${{ secrets.AWS_ACCESS_KEY_ID }}\naws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }}\nregion = ap-south-1" > ~/.aws/credentials
- name: SSH into the system and build binary
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: 'ap-south-1'
PRIVATE_KEY: ${{ secrets.AWS_PRIVATE_KEY }}
run: |
# echo $ref
ref=${{ github.event.ref }}
# echo tag
tag=$(echo "$ref" | sed 's/.*\///')
# get public IP of the linux machine
ip=$(dig +short myip.opendns.com @resolver1.opendns.com)
echo $ip
# set PAGER to empty to not get cli output automatically being sent to vim
export PAGER=
# whitelist the ip, add the ip to the security group to allow access into the instance
aws ec2 authorize-security-group-ingress --group-name pskr-sg --protocol tcp --port 22 --cidr $ip/32 --region ap-south-1
#start instance
aws ec2 start-instances --instance-ids i-05f5bb2b09b313386 --region ap-south-1 --output text
echo "starting instance..."
sleep 60
# get the public ip and status of the instance
public_ip=$(aws ec2 describe-instances --instance-ids i-05f5bb2b09b313386 --query 'Reservations[*].Instances[*].PublicDnsName' --region ap-south-1 --output text)
status=$(aws ec2 describe-instance-status --instance-ids i-05f5bb2b09b313386 --query 'InstanceStatuses[*].InstanceState.Name' --region ap-south-1 --output text)
echo $public_ip
echo $status
# check if the instance is available for use, if not, then wait for it
while [ $status != "running" ] ; do
echo "instance not yet available"
sleep 5
status=$(aws ec2 describe-instance-status --instance-ids i-05f5bb2b09b313386 --query 'InstanceStatuses[*].InstanceState.Name' --region ap-south-1 --output text)
done
# set up the private key
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
# ssh into the instance and run the script to build the binary
ssh -o StrictHostKeyChecking=accept-new -i private_key ubuntu@$public_ip 'bash -s' < scripts/script_to_build.sh $tag
# use scp to fetch the built binary out of the instance
scp -i private_key ubuntu@$public_ip:/home/ubuntu/steampipe-postgres-fdw/build-Linux/steampipe_postgres_fdw.so .
# stop instance
aws ec2 stop-instances --instance-ids i-05f5bb2b09b313386 --region ap-south-1
# remove the ip from the security group
aws ec2 revoke-security-group-ingress --group-name pskr-sg --protocol tcp --port 22 --cidr $ip/32 --region ap-south-1
# check binary exists
file steampipe_postgres_fdw.so
- name: gzip the steampipe_postgres_fdw.so
run: |-
gzip steampipe_postgres_fdw.so
mv steampipe_postgres_fdw.so.gz steampipe_postgres_fdw.so.linux_arm64.gz
- name: Save Linux Build Artifact - ARM64
uses: actions/upload-artifact@v4
with:
name: steampipe_postgres_fdw.so.linux_arm64
path: steampipe_postgres_fdw.so.linux_arm64.gz
if-no-files-found: error
build-draft-release:
name: Build Draft Release
runs-on: ubuntu-latest
needs:
- build-linux
- build-linux-arm
- build-osx
- build-osx-arm
steps:
- name: Get latest version tag
run: |-
echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Validate Version String
run: |-
if [[ $VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
echo "Version OK: $VERSION"
else
echo "Invalid version: $VERSION"
exit 1
fi
- name: Download steampipe_postgres_fdw.so - darwin_amd64
id: download_fdw_so_darwin_amd64
uses: actions/download-artifact@v4
with:
name: steampipe_postgres_fdw.so.darwin_amd64
- name: Download steampipe_postgres_fdw.so - darwin_arm64
id: download_fdw_so_darwin_arm64
uses: actions/download-artifact@v4
with:
name: steampipe_postgres_fdw.so.darwin_arm64
- name: Download steampipe_postgres_fdw.so - linux_amd64
id: download_fdw_so_linux_amd64
uses: actions/download-artifact@v4
with:
name: steampipe_postgres_fdw.so.linux_amd64
- name: Download steampipe_postgres_fdw.so - linux_arm64
id: download_fdw_so_linux_arm64
uses: actions/download-artifact@v4
with:
name: steampipe_postgres_fdw.so.linux_arm64
- name: Download steampipe_postgres_fdw.control
id: download_fdw_control
uses: actions/download-artifact@v4
with:
name: steampipe_postgres_fdw.control
- name: Download steampipe_postgres_fdw--1.0.sql
id: download_fdw_sql
uses: actions/download-artifact@v4
with:
name: steampipe_postgres_fdw--1.0.sql
- name: Check Path
run: |-
ls -la
- name: Create a draft release
uses: softprops/action-gh-release@v2
id: create_draft_release
with:
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
name: ${{ env.VERSION }}
tag_name: ${{ env.VERSION }}
repository: ${{ github.repository }}
files: |-
${{ steps.download_fdw_sql.outputs.download-path }}/steampipe_postgres_fdw--1.0.sql
${{ steps.download_fdw_control.outputs.download-path }}/steampipe_postgres_fdw.control
${{ steps.download_fdw_so_linux_amd64.outputs.download-path }}/steampipe_postgres_fdw.so.linux_amd64.gz
${{ steps.download_fdw_so_linux_arm64.outputs.download-path }}/steampipe_postgres_fdw.so.linux_arm64.gz
${{ steps.download_fdw_so_darwin_amd64.outputs.download-path }}/steampipe_postgres_fdw.so.darwin_amd64.gz
${{ steps.download_fdw_so_darwin_arm64.outputs.download-path }}/steampipe_postgres_fdw.so.darwin_arm64.gz