Skip to content

Commit b393a1f

Browse files
authored
Update linux arm building job and rename script to upload darwin arm binaries. Closes #221 (#222)
1 parent 63db8b1 commit b393a1f

File tree

5 files changed

+93
-80
lines changed

5 files changed

+93
-80
lines changed

.github/workflows/buildimage.yml

Lines changed: 63 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -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

build_arm_and_upload.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
# This script is used to build the ARM binaries and upload to the github draft release.
4+
# Just run this script from your Mac M1 or Linux ARM machine, if you want to build and upload the ARM binaries.
5+
6+
cd fdw
7+
make clean
8+
make go
9+
make
10+
make release
11+
cd -

build_release.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

fdw/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ inst:
5050
rm ./*.o
5151

5252
release:
53-
./upload_asset.sh
53+
./../upload_arm_asset.sh
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
#!/usr/bin/env bash
22

3+
ARCH=$(uname -m)
4+
# exit if the architecture is not arm64(darwin) or aarch64(linux)
5+
if [[ "$ARCH" != "arm64" ]] && [[ "$ARCH" != "aarch64" ]]; then
6+
echo "Not an ARM64 system"
7+
exit
8+
fi
9+
10+
# Must have these commands for the script to run
11+
declare -a required_commands=("gh" "gzip" "postgres")
12+
13+
for required_command in "${required_commands[@]}"
14+
do
15+
if [[ $(command -v $required_command | head -c1 | wc -c) -eq 0 ]]; then
16+
echo "$required_command is required for this script to run."
17+
exit -1
18+
fi
19+
done
20+
321
# get the tag_names of draft releases
422
TAG=$(gh api -X GET /repos/{owner}/{repo}/releases -F owner=turbot -F repo=steampipe --jq '.[] | select(.draft == true) | .tag_name')
523

0 commit comments

Comments
 (0)