Skip to content

Commit

Permalink
Workaround issue with mn gradle plugin when setting docker base image
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelaferreira committed Sep 3, 2023
1 parent 0cc97be commit 87f6f92
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ test {
}

tasks {
dockerfile {
baseImage = 'amazoncorretto:17-alpine3.18'
}
// TODO: set this configuration once issue https://github.com/micronaut-projects/micronaut-gradle-plugin/issues/820
// is solved.
// dockerfile {
// baseImage = 'amazoncorretto:17-alpine3.18'
// }

dockerBuild {
images = ["${System.env.DOCKER_IMAGE ?: project.name}:$project.version"]
Expand Down
10 changes: 10 additions & 0 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM amazoncorretto:17-alpine3.18

COPY build/libs/ses-notification-lambda-test-all.jar /home/not-root/application.jar

# Configure non-root user
RUN addgroup -g 3000 not-root \
&& adduser -u 1000 -s /bin/false -D -G not-root not-root
USER not-root

ENTRYPOINT ["java", "-jar", "/home/not-root/application.jar"]
16 changes: 16 additions & 0 deletions scripts/dockerBuildAndPush.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /usr/bin/env sh

###############################################################################
# This script is used in place of `./gradlew dockerPush` because of an issue
# that prevents us from selecting the base container issue we want to use.
#
# https://github.com/micronaut-projects/micronaut-gradle-plugin/issues/820
###############################################################################

if [ -z "${DOCKER_IMAGE}" ]; then
echo "Need a container image in env var DOCKER_IMAGE" && exit 1
fi

./gradlew assemble
docker build . -f scripts/Dockerfile -t "${DOCKER_IMAGE}"
docker push "${DOCKER_IMAGE}"
5 changes: 4 additions & 1 deletion terraform/build-container.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ resource "null_resource" "build_container" {
provisioner "local-exec" {
working_dir = dirname(path.cwd)

command = "DOCKER_IMAGE=${local.container_image} ./gradlew dockerPush"
command = "DOCKER_IMAGE=${local.container_image} scripts/dockerBuildAndPush.sh"
# TODO: use gradle task dockerPush when issue https://github.com/micronaut-projects/micronaut-gradle-plugin/issues/820
# has been solved.
# command = "DOCKER_IMAGE=${local.container_image} ./gradlew dockerPush"
}

depends_on = [null_resource.login_ecr]
Expand Down

0 comments on commit 87f6f92

Please sign in to comment.