Skip to content

Commit

Permalink
chore: Move docker images to component directories
Browse files Browse the repository at this point in the history
  • Loading branch information
niallthomson committed Jul 13, 2024
1 parent f11457a commit 329b805
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 55 deletions.
67 changes: 67 additions & 0 deletions src/cart/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Build Stage
FROM public.ecr.aws/amazonlinux/amazonlinux:2023 as build-env

# We tell DNF not to install Recommends and Suggests packages, keeping our
# installed set of packages as minimal as possible.
RUN dnf --setopt=install_weak_deps=False install -q -y \
maven \
java-17-amazon-corretto-headless \
which \
&& \
dnf clean all

ARG JAR_PATH

VOLUME /tmp
WORKDIR /

COPY .mvn .mvn
COPY mvnw .
COPY pom.xml .

RUN ./mvnw dependency:go-offline -B -q

COPY ./src ./src

RUN ./mvnw -DskipTests package -q && \
mv /target/carts-0.0.1-SNAPSHOT.jar /app.jar

# Package Stage
FROM public.ecr.aws/amazonlinux/amazonlinux:2023

# We tell DNF not to install Recommends and Suggests packages, which are
# weak dependencies in DNF terminology, thus keeping our installed set of
# packages as minimal as possible.
RUN dnf --setopt=install_weak_deps=False install -q -y \
java-17-amazon-corretto-headless \
shadow-utils \
&& \
dnf clean all

ARG aws_opentelemetry_agent_version=1.24.0

ENV APPUSER=appuser
ENV APPUID=1000
ENV APPGID=1000

RUN useradd \
--home "/app" \
--create-home \
--user-group \
--uid "$APPUID" \
"$APPUSER"

RUN curl -L https://github.com/aws-observability/aws-otel-java-instrumentation/releases/download/v${aws_opentelemetry_agent_version}/aws-opentelemetry-agent.jar -o /opt/aws-opentelemetry-agent.jar && \
curl -L https://raw.githubusercontent.com/aws-observability/aws-otel-java-instrumentation/v${aws_opentelemetry_agent_version}/licenses/licenses.md -o aws-opentelemetry-agent-licenses.md
ENV JAVA_TOOL_OPTIONS=-javaagent:/opt/aws-opentelemetry-agent.jar
ENV OTEL_JAVAAGENT_ENABLED=false

WORKDIR /app
USER appuser

COPY ./ATTRIBUTION.md ./LICENSES.md
COPY --chown=appuser:appuser --from=build-env /app.jar .

EXPOSE 8080

ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"]
12 changes: 5 additions & 7 deletions src/cart/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
version: '2.3'
version: "2.3"

services:
carts:
build:
context: .
dockerfile: ../../images/java17/Dockerfile
args:
JAR_PATH: target/carts-0.0.1-SNAPSHOT.jar
image: microservices-demo/carts
hostname: carts
restart: always
Expand All @@ -29,7 +26,8 @@ services:
ports:
- "8082:8080"
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8080/actuator/health || exit 1"]
test:
["CMD-SHELL", "curl -f http://localhost:8080/actuator/health || exit 1"]
interval: 10s
timeout: 10s
retries: 3
Expand Down Expand Up @@ -61,7 +59,7 @@ services:

waiter:
image: busybox:1.33.0
restart: 'no'
restart: "no"
cap_drop:
- all
read_only: true
Expand All @@ -70,4 +68,4 @@ services:
command: echo 'Ready'
depends_on:
carts:
condition: service_healthy
condition: service_healthy
2 changes: 0 additions & 2 deletions src/cart/scripts/build.source

This file was deleted.

4 changes: 1 addition & 3 deletions images/go/Dockerfile → src/catalog/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ RUN dnf --setopt=install_weak_deps=False install -q -y \
&& \
dnf clean all

ARG MAIN_PATH

RUN mkdir -p "${GOPATH}/src" "${GOPATH}/bin" /appsrc

WORKDIR /appsrc

COPY . .

ENV GOPROXY=direct
RUN go build -o main $MAIN_PATH
RUN go build -o main main.go

# Final stage
FROM public.ecr.aws/amazonlinux/amazonlinux:2023
Expand Down
3 changes: 0 additions & 3 deletions src/catalog/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ services:
catalog:
build:
context: .
dockerfile: ../../images/go/Dockerfile
args:
MAIN_PATH: main.go
image: microservices-demo/catalog
hostname: catalog
depends_on:
Expand Down
1 change: 0 additions & 1 deletion src/catalog/scripts/build.source
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
dockerfile='../../images/go/Dockerfile'
pack_args='--env BP_KEEP_FILES=db/*'
File renamed without changes.
11 changes: 5 additions & 6 deletions src/checkout/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ services:
checkout:
build:
context: .
dockerfile: ../../images/nodejs/Dockerfile
image: microservices-demo/checkout
hostname: checkout
restart: always
Expand All @@ -18,9 +17,9 @@ services:
environment:
- REDIS_URL=redis://checkout-redis:6379
ports:
- "8085:8080"
- '8085:8080'
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"]
test: ['CMD-SHELL', 'curl -f http://localhost:8080/health || exit 1']
interval: 10s
timeout: 10s
retries: 3
Expand All @@ -33,9 +32,9 @@ services:
hostname: checkout-redis
restart: always
ports:
- "6379:6379"
- '6379:6379'
healthcheck:
test: ["CMD", "redis-cli", "ping"]
test: ['CMD', 'redis-cli', 'ping']
interval: 1s
timeout: 3s
retries: 30
Expand All @@ -48,4 +47,4 @@ services:
command: echo 'Ready'
depends_on:
checkout:
condition: service_healthy
condition: service_healthy
1 change: 0 additions & 1 deletion src/checkout/scripts/build.source

This file was deleted.

67 changes: 67 additions & 0 deletions src/orders/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Build Stage
FROM public.ecr.aws/amazonlinux/amazonlinux:2023 as build-env

# We tell DNF not to install Recommends and Suggests packages, keeping our
# installed set of packages as minimal as possible.
RUN dnf --setopt=install_weak_deps=False install -q -y \
maven \
java-17-amazon-corretto-headless \
which \
&& \
dnf clean all

ARG JAR_PATH

VOLUME /tmp
WORKDIR /

COPY .mvn .mvn
COPY mvnw .
COPY pom.xml .

RUN ./mvnw dependency:go-offline -B -q

COPY ./src ./src

RUN ./mvnw -DskipTests package -q && \
mv /target/orders-0.0.1-SNAPSHOT.jar /app.jar

# Package Stage
FROM public.ecr.aws/amazonlinux/amazonlinux:2023

# We tell DNF not to install Recommends and Suggests packages, which are
# weak dependencies in DNF terminology, thus keeping our installed set of
# packages as minimal as possible.
RUN dnf --setopt=install_weak_deps=False install -q -y \
java-17-amazon-corretto-headless \
shadow-utils \
&& \
dnf clean all

ARG aws_opentelemetry_agent_version=1.24.0

ENV APPUSER=appuser
ENV APPUID=1000
ENV APPGID=1000

RUN useradd \
--home "/app" \
--create-home \
--user-group \
--uid "$APPUID" \
"$APPUSER"

RUN curl -L https://github.com/aws-observability/aws-otel-java-instrumentation/releases/download/v${aws_opentelemetry_agent_version}/aws-opentelemetry-agent.jar -o /opt/aws-opentelemetry-agent.jar && \
curl -L https://raw.githubusercontent.com/aws-observability/aws-otel-java-instrumentation/v${aws_opentelemetry_agent_version}/licenses/licenses.md -o aws-opentelemetry-agent-licenses.md
ENV JAVA_TOOL_OPTIONS=-javaagent:/opt/aws-opentelemetry-agent.jar
ENV OTEL_JAVAAGENT_ENABLED=false

WORKDIR /app
USER appuser

COPY ./ATTRIBUTION.md ./LICENSES.md
COPY --chown=appuser:appuser --from=build-env /app.jar .

EXPOSE 8080

ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"]
3 changes: 0 additions & 3 deletions src/orders/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ services:
orders:
build:
context: .
dockerfile: ../../images/java17/Dockerfile
args:
JAR_PATH: target/orders-0.0.1-SNAPSHOT.jar
image: microservices-demo/orders
hostname: orders
restart: always
Expand Down
2 changes: 0 additions & 2 deletions src/orders/scripts/build.source

This file was deleted.

4 changes: 1 addition & 3 deletions images/java17/Dockerfile → src/ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ RUN dnf --setopt=install_weak_deps=False install -q -y \
&& \
dnf clean all

ARG JAR_PATH

VOLUME /tmp
WORKDIR /

Expand All @@ -24,7 +22,7 @@ RUN ./mvnw dependency:go-offline -B -q
COPY ./src ./src

RUN ./mvnw -DskipTests package -q && \
mv /$JAR_PATH /app.jar
mv /target/ui-0.0.1-SNAPSHOT.jar /app.jar

# Package Stage
FROM public.ecr.aws/amazonlinux/amazonlinux:2023
Expand Down
25 changes: 3 additions & 22 deletions src/ui/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

version: '2'
version: "2"

services:
ui:
ports:
- 8080
- 8080
environment:
- JAVA_OPTS=-XX:MaxRAMPercentage=75.0 -Djava.security.egd=file:/dev/urandom
- SERVER_TOMCAT_ACCESSLOG_ENABLED=true
hostname: ui
build:
context: .
dockerfile: ../../images/java17/Dockerfile
args:
JAR_PATH: target/ui-0.0.1-SNAPSHOT.jar
image: microservices-demo/ui
restart: always
mem_limit: 256m
cap_drop:
- ALL
- ALL
2 changes: 0 additions & 2 deletions src/ui/scripts/build.source

This file was deleted.

0 comments on commit 329b805

Please sign in to comment.