Skip to content
This repository was archived by the owner on Sep 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 54 additions & 33 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release

on:
push:
branches: ["main"]
branches: [ "main" ]
tags: [ v* ]
# pull_request:
# types: [ opened, synchronize, reopened ]
Expand All @@ -14,27 +14,23 @@ on:
permissions:
id-token: write
contents: read
packages: write

jobs:
env:
APP_VERSION: ${{ github.ref_type == 'tag' && github.ref_name || github.event.pull_request.head.sha || github.sha }}

release:
jobs:
release-ami:
runs-on: ubuntu-latest
name: "Release"
name: "Release AMI"
env:
AWS_REGION: eu-central-1
APP_VERSION: ${{ github.ref_type == 'tag' && github.ref_name || github.event.pull_request.head.sha || github.sha }}
ARTIFACTS_BUCKET: priceloop-build-artifacts-nocode
POSTGRES_REPOSITORY: priceloop/postgres
ECR_URL: public.ecr.aws
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Build Docker
run: >
docker build . -t ${ECR_URL}/${POSTGRES_REPOSITORY}:${APP_VERSION}

- name: Generate github token
id: generate-token
uses: tibdex/github-app-token@v1
Expand All @@ -55,79 +51,104 @@ jobs:
aws s3 cp --recursive postgres_extension s3://${ARTIFACTS_BUCKET}/nocode-postgres/${APP_VERSION}/postgres_extension
aws s3 cp --recursive postgres_config s3://${ARTIFACTS_BUCKET}/nocode-postgres/${APP_VERSION}/postgres_config

- name: Publish Docker Images
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws

docker push ${ECR_URL}/${POSTGRES_REPOSITORY}:${APP_VERSION}

- name: AMI Build
run: |
export AWS_ACCOUNT_ID="$(aws sts get-caller-identity | jq -r '.Account')"

export APP_VERSION_SANE="$(echo $APP_VERSION | sed 's/\./-/g')"
envsubst < image-recipe.tpl.json | tee image-recipe.json
aws imagebuilder create-image-recipe --cli-input-json file://image-recipe.json > /dev/null

IMAGE_BUILD_ARN=$(aws imagebuilder create-image \
--image-tests-configuration "imageTestsEnabled=false" \
--image-recipe-arn "arn:aws:imagebuilder:${AWS_REGION}:${AWS_ACCOUNT_ID}:image-recipe/nocode-postgres-ami-${APP_VERSION_SANE}/1.0.0" \
--infrastructure-configuration-arn "arn:aws:imagebuilder:${AWS_REGION}:${AWS_ACCOUNT_ID}:infrastructure-configuration/nocode-postgres-ami" \
--distribution-configuration-arn "arn:aws:imagebuilder:${AWS_REGION}:${AWS_ACCOUNT_ID}:distribution-configuration/nocode-postgres-ami" \
| jq -r '.imageBuildVersionArn')

echo "Building: $IMAGE_BUILD_ARN"

BUILD_STATUS=""
while [[ -z "$(echo $BUILD_STATUS | grep -E '^(AVAILABLE|CANCELLED|FAILED|DEPRECATED|DELETED)$')" ]]; do
sleep 30
BUILD_STATUS=$(aws imagebuilder get-image --image-build-version-arn "$IMAGE_BUILD_ARN" | jq -r '.image.state.status')
echo "Waiting for AMI...${BUILD_STATUS}"
done

if [[ "$BUILD_STATUS" != "AVAILABLE" ]]; then
echo "AMI Build failed"
exit 1
fi

AMI_ID="$(aws imagebuilder get-image --image-build-version-arn "$IMAGE_BUILD_ARN" | jq -r '.image.outputResources.amis[0].image')"
echo "AMI: $AMI_ID"

echo $AMI_ID > ami_id
aws s3 cp --content-type "text/plain" ami_id s3://${ARTIFACTS_BUCKET}/nocode-postgres/${APP_VERSION}/ami_id


release-docker-image:
runs-on: ubuntu-latest
name: "Release Docker Image"
env:
AWS_REGION: eu-central-1
# ARTIFACTS_BUCKET: priceloop-build-artifacts-nocode
DOCKER_IMAGE: priceloop/nocode-postgres
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Build and Publish Docker Images
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u USERNAME --password-stdin
docker buildx build \
--platform linux/arm64,linux/amd64 \
--tag ghcr.io/${DOCKER_IMAGE}:${APP_VERSION} \
--label "org.opencontainers.image.source=https://github.com/priceloop/nocode-postgres" \
--label "org.opencontainers.image.description=Postgres Image for Nocode" \
--label "org.opencontainers.image.licenses=MIT" \
--push \
.

nocode-repo:
name: "Push version to nocode-repo"
if: github.ref_type == 'tag'
needs: [ "release-docker-image", "release-ami" ]
runs-on: ubuntu-latest
steps:
- name: Version
run: |
echo "Version: ${APP_VERSION}"

- name: Generate github token
id: generate-token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.GH_APP_ID }}
private_key: ${{ secrets.GH_PRIVATE_KEY }}

- name: Checkout nocode repository
if: github.ref_type == 'tag'
uses: actions/checkout@v3
with:
token: ${{ steps.generate-token.outputs.token }}
repository: priceloop/nocode
path: nocode

- name: Update nocode repository
if: github.ref_type == 'tag'
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
cd nocode/

git config user.name "priceloop"
git config user.email "ogopogo@priceloop.ai"

git checkout -b "postgres-${APP_VERSION}"

source .envrc
sed "s/NOCODE_POSTGRES_VERSION=\"${NOCODE_POSTGRES_VERSION}\"/NOCODE_POSTGRES_VERSION=\"${APP_VERSION}\"/" -i .envrc

git diff --stat
git commit -am "chore: update nocode postgres version to ${APP_VERSION}"

git log --oneline --max-count=10

git push --set-upstream origin "postgres-${APP_VERSION}"

gh pr create -f
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/image-recipe.json
*.o
*.so
Binary file removed postgres_extension/functions/functions.so
Binary file not shown.