Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build and deploy on GHA #49

Merged
merged 30 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
971a715
WIP - compile native image, build docker image.
ychescale9 Aug 13, 2024
d3a2105
Try `macos-13` with 14 GB RAM.
ychescale9 Aug 13, 2024
126af45
Re-generate configs, set max heap, set `-match=native`. Revert to `u…
ychescale9 Aug 13, 2024
ea8f898
Build native executable in docker multistage build.
ychescale9 Aug 13, 2024
21b2942
Revert to building outside of image.
ychescale9 Aug 13, 2024
55e52cd
WIP try to push container image to GAR.
ychescale9 Aug 13, 2024
deb1857
Fix envvar
ychescale9 Aug 13, 2024
1042c1b
WIP - deploy to cloud run.
ychescale9 Aug 13, 2024
6fe63d6
Fix env
ychescale9 Aug 13, 2024
8a7546c
ensure executable
ychescale9 Aug 13, 2024
378f2d4
Remove chmod.
ychescale9 Aug 13, 2024
c4b84ac
Multi stage build.
ychescale9 Aug 13, 2024
9026f45
Revert to building outside, try `oraclelinux:8-slim`, disable docker …
ychescale9 Aug 14, 2024
dfa5666
Re-enable docker buildx.
ychescale9 Aug 14, 2024
097ef8b
build executable in multi-stage build
ychescale9 Aug 14, 2024
846080a
Fix path
ychescale9 Aug 14, 2024
9369d4f
Try alpine
ychescale9 Aug 14, 2024
000ac53
switch to `ubuntu`
ychescale9 Aug 14, 2024
dc064ee
Remove `march=native`. Build executable outside.
ychescale9 Aug 14, 2024
4710584
Build in image.
ychescale9 Aug 14, 2024
9b13ecc
8g ram
ychescale9 Aug 14, 2024
d9097f9
Update `reflect-config.json`. Build outside.
ychescale9 Aug 14, 2024
aebff96
Add missing reflection configs. Temporarily enable gradle cache write.
ychescale9 Aug 14, 2024
169b4bc
Simplify reflection configs for DGS generated types. google-github-ac…
ychescale9 Aug 14, 2024
26ebba2
Delete cloudbuild.yaml.
ychescale9 Aug 14, 2024
3d5c6eb
Add shot sha to tag.
ychescale9 Aug 14, 2024
4620113
add `build` label instead
ychescale9 Aug 14, 2024
da5fb10
Revert to tagging sha and latest. Disable multi arch build.
ychescale9 Aug 14, 2024
3c47107
Clean up old images after deployment.
ychescale9 Aug 14, 2024
016a06b
clean up
ychescale9 Aug 14, 2024
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
82 changes: 81 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,91 @@ jobs:

steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '22'

- uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
- run: ./gradlew assemble check --no-configuration-cache

- run: ./gradlew assemble check
deploy:
name: Build and push container image to Google Artifact Registry, deploy to Cloud Run
needs: [ assemble-and-check ]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
env:
CONTAINER_IMAGE: ${{ secrets.GCP_CONTAINER_IMAGE }}
REGION: ${{ secrets.GCP_REGION }}
SERVICE_NAME: ${{ secrets.GCP_SERVICE_NAME }}
CPU: 4
MEMORY: 2Gi
MIN_INSTANCES: 0
MAX_INSTANCES: 4
REQUEST_TIMEOUT: 30s

steps:
- uses: actions/checkout@v4

- uses: graalvm/setup-graalvm@v1
with:
distribution: 'graalvm-community'
java-version: '22'
github-token: ${{ secrets.GITHUB_TOKEN }}

- uses: gradle/actions/setup-gradle@v4

- name: Build GraalVM native executable
run: ./gradlew nativeCompile --no-configuration-cache

- uses: docker/login-action@v3
with:
registry: ${{ env.REGION }}-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCP_CREDENTIALS_JSON }}

- name: Add environment variable for short SHA
run: echo "SHA_SHORT=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"

- name: Build and push container image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.CONTAINER_IMAGE }}:${{ env.SHA_SHORT }},${{ env.CONTAINER_IMAGE }}:latest

- uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS_JSON }}

- uses: google-github-actions/setup-gcloud@v2

- name: Deploy to Cloud Run
run: |
gcloud run deploy ${{ env.SERVICE_NAME }} \
--image ${{ env.CONTAINER_IMAGE }}:${{ env.SHA_SHORT }} \
--region ${{ env.REGION }} \
--cpu ${{ env.CPU }} \
--memory ${{ env.MEMORY }} \
--timeout ${{ env.REQUEST_TIMEOUT }} \
--min-instances ${{ env.MIN_INSTANCES }} \
--max-instances ${{ env.MAX_INSTANCES }} \
--platform managed \
--allow-unauthenticated

- name: Cleanup old images
run: |
# Get all images except the most recent 2
IMAGES_TO_DELETE=$(gcloud artifacts docker images list ${{ env.CONTAINER_IMAGE }} \
--format="get(DIGEST)" \
--sort-by="~CREATE_TIME" | tail -n +3)

# Delete the older images
for DIGEST in $IMAGES_TO_DELETE; do
gcloud artifacts docker images delete ${{ env.CONTAINER_IMAGE }}@$DIGEST \
--delete-tags \
--quiet
done
18 changes: 3 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
# Build stage
FROM ghcr.io/graalvm/graalvm-community:22 as build
FROM ubuntu:latest

WORKDIR /app
COPY build/native/nativeCompile/kstreamlined-backend /app/kstreamlined-backend

COPY . /app

RUN ./gradlew nativeCompile --no-configuration-cache

# Runtime stage
FROM scratch

COPY --from=build /app/build/native/nativeCompile/kstreamlined-backend /app

ENTRYPOINT ["/app/"]

EXPOSE 8000
ENTRYPOINT ["/app/kstreamlined-backend"]
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ graalvmNative {
vendor.set(JvmVendorSpec.GRAAL_VM)
}
resources.autodetect()
buildArgs(
"-R:MaxHeapSize=100m",
)
}
}

Expand Down
28 changes: 0 additions & 28 deletions cloudbuild.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"type":"agent-extracted",
"classes":[
]
}
]

64 changes: 52 additions & 12 deletions src/main/resources/META-INF/native-image/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -945,36 +945,36 @@
},
{
"name":"io.github.reactivecircus.kstreamlined.backend.schema.generated.types.FeedSource",
"queryAllDeclaredMethods":true,
"methods":[{"name":"getDescription","parameterTypes":[] }, {"name":"getKey","parameterTypes":[] }, {"name":"getTitle","parameterTypes":[] }]
"allDeclaredFields":true,
"allDeclaredMethods":true
},
{
"name":"io.github.reactivecircus.kstreamlined.backend.schema.generated.types.FeedSourceKey"
},
{
"name":"io.github.reactivecircus.kstreamlined.backend.schema.generated.types.KotlinBlog",
"queryAllDeclaredMethods":true,
"methods":[{"name":"getContentUrl","parameterTypes":[] }, {"name":"getDescription","parameterTypes":[] }, {"name":"getFeaturedImageUrl","parameterTypes":[] }, {"name":"getId","parameterTypes":[] }, {"name":"getPublishTime","parameterTypes":[] }, {"name":"getTitle","parameterTypes":[] }]
"allDeclaredFields":true,
"allDeclaredMethods":true
},
{
"name":"io.github.reactivecircus.kstreamlined.backend.schema.generated.types.KotlinWeekly",
"queryAllDeclaredMethods":true,
"methods":[{"name":"getContentUrl","parameterTypes":[] }, {"name":"getId","parameterTypes":[] }, {"name":"getPublishTime","parameterTypes":[] }, {"name":"getTitle","parameterTypes":[] }]
"allDeclaredFields":true,
"allDeclaredMethods":true
},
{
"name":"io.github.reactivecircus.kstreamlined.backend.schema.generated.types.KotlinWeeklyIssueEntry",
"queryAllDeclaredMethods":true,
"methods":[{"name":"getGroup","parameterTypes":[] }, {"name":"getSource","parameterTypes":[] }, {"name":"getSummary","parameterTypes":[] }, {"name":"getTitle","parameterTypes":[] }, {"name":"getUrl","parameterTypes":[] }]
"allDeclaredFields":true,
"allDeclaredMethods":true
},
{
"name":"io.github.reactivecircus.kstreamlined.backend.schema.generated.types.KotlinYouTube",
"queryAllDeclaredMethods":true,
"methods":[{"name":"getContentUrl","parameterTypes":[] }, {"name":"getDescription","parameterTypes":[] }, {"name":"getId","parameterTypes":[] }, {"name":"getPublishTime","parameterTypes":[] }, {"name":"getThumbnailUrl","parameterTypes":[] }, {"name":"getTitle","parameterTypes":[] }]
"allDeclaredFields":true,
"allDeclaredMethods":true
},
{
"name":"io.github.reactivecircus.kstreamlined.backend.schema.generated.types.TalkingKotlin",
"queryAllDeclaredMethods":true,
"methods":[{"name":"getContentUrl","parameterTypes":[] }, {"name":"getDuration","parameterTypes":[] }, {"name":"getId","parameterTypes":[] }, {"name":"getPublishTime","parameterTypes":[] }, {"name":"getSummary","parameterTypes":[] }, {"name":"getThumbnailUrl","parameterTypes":[] }, {"name":"getTitle","parameterTypes":[] }]
"allDeclaredFields":true,
"allDeclaredMethods":true
},
{
"name":"io.ktor.client.HttpClient",
Expand Down Expand Up @@ -4279,10 +4279,30 @@
"name":"reactor.core.publisher.FluxFirstWithSignal$RaceCoordinator",
"fields":[{"name":"winner"}]
},
{
"name":"reactor.core.publisher.FluxGenerate$GenerateSubscription",
"fields":[{"name":"requested"}]
},
{
"name":"reactor.core.publisher.FluxIterable$IterableSubscription",
"fields":[{"name":"requested"}]
},
{
"name":"reactor.core.publisher.FluxLimitRequest$FluxLimitRequestSubscriber",
"fields":[{"name":"requestRemaining"}]
},
{
"name":"reactor.core.publisher.FluxOnErrorReturn$ReturnSubscriber",
"fields":[{"name":"requested"}]
},
{
"name":"reactor.core.publisher.FluxSubscribeOn$SubscribeOnSubscriber",
"fields":[{"name":"requested"}, {"name":"s"}, {"name":"thread"}]
},
{
"name":"reactor.core.publisher.FluxUsing$UsingFuseableSubscriber",
"fields":[{"name":"wip"}]
},
{
"name":"reactor.core.publisher.Hooks"
},
Expand Down Expand Up @@ -4321,6 +4341,10 @@
"name":"reactor.core.publisher.MonoNext$NextSubscriber",
"fields":[{"name":"wip"}]
},
{
"name":"reactor.core.publisher.MonoSubscribeOn$SubscribeOnSubscriber",
"fields":[{"name":"requested"}, {"name":"s"}, {"name":"thread"}]
},
{
"name":"reactor.core.publisher.MonoWhen$WhenCoordinator",
"fields":[{"name":"state"}]
Expand Down Expand Up @@ -4365,6 +4389,10 @@
"name":"reactor.core.scheduler.BoundedElasticScheduler$BoundedState",
"fields":[{"name":"markCount"}]
},
{
"name":"reactor.core.scheduler.WorkerTask",
"fields":[{"name":"future"}, {"name":"parent"}, {"name":"thread"}]
},
{
"name":"reactor.netty.channel.ChannelOperations",
"fields":[{"name":"outboundSubscription"}]
Expand All @@ -4377,6 +4405,10 @@
"name":"reactor.netty.channel.FluxReceive",
"fields":[{"name":"receiverCancel"}]
},
{
"name":"reactor.netty.channel.MonoSendMany$SendManyInner",
"fields":[{"name":"s"}, {"name":"wip"}]
},
{
"name":"reactor.netty.contextpropagation.ChannelContextAccessor"
},
Expand Down Expand Up @@ -4425,6 +4457,14 @@
{
"name":"reactor.tools.agent.ReactorDebugAgent"
},
{
"name":"reactor.util.concurrent.SpscArrayQueueConsumer",
"fields":[{"name":"consumerIndex"}]
},
{
"name":"reactor.util.concurrent.SpscArrayQueueProducer",
"fields":[{"name":"producerIndex"}]
},
{
"name":"reactor.util.context.ReactorContextAccessor"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"types":[
],
"lambdaCapturingTypes":[
],
"proxies":[
]
}