@@ -265,93 +265,84 @@ jobs:
265265 - name : Checkout
266266 uses : actions/checkout@v3
267267
268- - name : Build and upload binary
269- uses : uraimo/run-on-arch-action@v2
268+ - name : Configure AWS Credentials
269+ run : |
270+ mkdir ~/.aws
271+ 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
272+
273+ - name : SSH into the system and build binary
270274 env :
271- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
272- with :
273- arch : aarch64
274- distro : ubuntu_latest
275- # Create an artifacts directory
276- setup : |
277- mkdir -p "${PWD}/artifacts"
278- # Mount the artifacts directory as /artifacts in the container
279- dockerRunArgs : |
280- --volume "${PWD}/artifacts:/artifacts"
281- env : |
282- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
283- run : |
284- echo "update apt and install necessary packages"
285- apt-get update -y
286- apt-get -y install sudo git curl tar gzip file postgresql-server-dev-14 build-essential make
287-
288- echo "install go"
289- curl -LO https://go.dev/dl/go1.18beta1.linux-arm64.tar.gz
290- tar -C /usr/local -xzf go1.18beta1.linux-arm64.tar.gz
291- export GOROOT=/usr/local/go
292- export GOPATH=$HOME/go
293- export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
294- go version
295-
296- echo "find stuff and set env"
297- which pg_config
298- pg_config --version
299- export PATH=$(pg_config --bindir):$PATH
300- export PGXS=$(pg_config --pgxs)
301- export SERVER_LIB=$(pg_config --includedir)/server
302- export INTERNAL_LIB=$(pg_config --includedir)/internal
303- export CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
304- export PG_CFLAGS="$(pg_config --cflags) -I${SERVER_LIB} -I${INTERNAL_LIB} -g"
305- export LDFLAGS=$(pg_config --ldflags)
306- export PG_LDFLAGS=$(pg_config --ldflags)
307-
308- echo "clone repo"
309- git clone https://github.com/turbot/steampipe-postgres-fdw.git
310- git config --global --add safe.directory /home/runner/work/steampipe-postgres-fdw/steampipe-postgres-fdw
311- git init
312- git fetch
313- pwd
314- git checkout ${{ github.event.inputs.tag }}
315- cd steampipe-postgres-fdw/fdw
316-
317- echo "make clean"
318- go version
319- make clean
320-
321- echo "make go"
322- make go
323-
324- echo "make"
325- make
326-
327- echo "check binary and copy into artifacts directory"
328- file steampipe_postgres_fdw.so
329- gzip steampipe_postgres_fdw.so
330- mv steampipe_postgres_fdw.so.gz steampipe_postgres_fdw.so.linux_arm64.gz
331- ls
332- cp steampipe_postgres_fdw.so.linux_arm64.gz /artifacts
333- ls -al /artifacts
334-
335- - name : Show the artifact
336- # Items placed in /artifacts in the container will be in
337- # ${PWD}/artifacts on the host.
275+ AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
276+ AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
277+ AWS_DEFAULT_REGION : ' ap-south-1'
278+ PRIVATE_KEY : ${{ secrets.AWS_PRIVATE_KEY }}
338279 run : |
339- ls -al "${PWD}/artifacts"
280+
281+ # get public IP of the linux machine
282+ ip=$(dig +short myip.opendns.com @resolver1.opendns.com)
283+ echo $ip
284+
285+ # set PAGER to empty to not get cli output automatically being sent to vim
286+ export PAGER=
287+
288+ # whitelist the ip, add the ip to the security group to allow access into the instance
289+ aws ec2 authorize-security-group-ingress --group-name pskr-sg --protocol tcp --port 22 --cidr $ip/32 --region ap-south-1
290+
291+ #start instance
292+ aws ec2 start-instances --instance-ids i-059a0baa5fb90a263 --region ap-south-1 --output text
293+ echo "starting instance..."
294+ sleep 60
295+
296+ # get the public ip and status of the instance
297+ public_ip=$(aws ec2 describe-instances --instance-ids i-059a0baa5fb90a263 --query 'Reservations[*].Instances[*].PublicDnsName' --region ap-south-1 --output text)
298+ status=$(aws ec2 describe-instance-status --instance-ids i-059a0baa5fb90a263 --query 'InstanceStatuses[*].InstanceState.Name' --region ap-south-1 --output text)
299+ echo $public_ip
300+ echo $status
301+
302+ # check if the instance is available for use, if not, then wait for it
303+ while [ $status != "running" ] ; do
304+ echo "instance not yet available"
305+ sleep 5
306+ status=$(aws ec2 describe-instance-status --instance-ids i-059a0baa5fb90a263 --query 'InstanceStatuses[*].InstanceState.Name' --region ap-south-1 --output text)
307+ done
308+
309+ # set up the private key
310+ echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
311+
312+ # ssh into the instance and run the set of commands to build
313+ ssh -o StrictHostKeyChecking=accept-new -i private_key ubuntu@$public_ip 'cat test.txt; uname -m; cd steampipe-postgres-fdw; git checkout main; git pull; git checkout $VERSION; rm -rf build-Linux; ./build.sh; exit 0'
314+
315+ # use scp to fetch the built binary out of the instance
316+ scp -i private_key ubuntu@$public_ip:/home/ubuntu/steampipe-postgres-fdw/build-Linux/steampipe_postgres_fdw.so .
317+
318+ # stop instance
319+ aws ec2 stop-instances --instance-ids i-059a0baa5fb90a263 --region ap-south-1
320+
321+ # remove the ip from the security group
322+ aws ec2 revoke-security-group-ingress --group-name pskr-sg --protocol tcp --port 22 --cidr $ip/32 --region ap-south-1
323+
324+ # check binary exists
325+ file steampipe_postgres_fdw.so
326+
327+ - name : gzip the steampipe_postgres_fdw.so
328+ run : |-
329+ gzip steampipe_postgres_fdw.so
330+ mv steampipe_postgres_fdw.so.gz steampipe_postgres_fdw.so.linux_arm64.gz
340331
341332 - name : Save Linux Build Artifact - ARM64
342333 uses : actions/upload-artifact@v3
343334 with :
344335 name : steampipe_postgres_fdw.so.linux_arm64
345- path : /home/runner/work/steampipe-postgres-fdw/steampipe-postgres-fdw/artifacts/ steampipe_postgres_fdw.so.linux_arm64.gz
336+ path : steampipe_postgres_fdw.so.linux_arm64.gz
346337 if-no-files-found : error
347338
348339 build-draft-release :
349340 name : Build Draft Release
350341 runs-on : ubuntu-latest
351342 needs :
352343 - build-linux
353- - build-osx
354344 - build-linux-arm
345+ - build-osx
355346 steps :
356347
357348 - name : Get latest version tag
0 commit comments