Skip to content

Commit

Permalink
change gwa-api to multistage docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
rustyjux committed Oct 25, 2024
1 parent 6a39b2f commit 5f515b2
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions microservices/gatewayApi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
# FROM golang:1.15.2 AS build
# WORKDIR /deck
# RUN git clone https://github.com/kong/deck.git
# RUN cd deck \
# && go mod download \
# && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o deck \
# -ldflags "-s -w -X github.com/kong/deck/cmd.VERSION=$TAG -X github.com/kong/deck/cmd.COMMIT=$COMMIT"
FROM python:3.11-alpine3.20
# Build stage
FROM python:3.11-alpine3.20 AS builder

RUN mkdir /.kube
WORKDIR /app

RUN chmod ugo+rw /.kube
RUN apk add --no-cache build-base libffi-dev openssl-dev curl

WORKDIR /app
# Install poetry
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python - --version 1.8.2 && \
ln -s /opt/poetry/bin/poetry /usr/local/bin/poetry && \
poetry config virtualenvs.create false

RUN apk add build-base libffi-dev openssl openssl-dev curl
# Install dependencies
COPY pyproject.toml poetry.lock ./
RUN poetry install --no-root --no-dev

# Download kubectl
RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" && \
chmod +x kubectl; mv kubectl /usr/local/bin/.
chmod +x kubectl

#COPY --from=build /deck/deck /usr/local/bin

# gwa api v1/v2
# Download deck v1.5.0
RUN curl -sL https://github.com/kong/deck/releases/download/v1.5.0/deck_1.5.0_linux_amd64.tar.gz -o deck.tar.gz && \
tar -xf deck.tar.gz -C /tmp && \
cp /tmp/deck /usr/local/bin/
tar -xf deck.tar.gz -C /tmp && \
mv /tmp/deck /usr/local/bin/deck

# gwa api v3
# Download deck v1.27.1
RUN curl -sL https://github.com/Kong/deck/releases/download/v1.27.1/deck_1.27.1_linux_amd64.tar.gz -o deck.tar.gz && \
tar -xf deck.tar.gz -C /tmp && \
cp /tmp/deck /usr/local/bin/deck127

RUN python -m pip install --upgrade pip
# FIX: No module named 'urllib3.packages.six'
RUN pip uninstall urllib3 && pip install urllib3
RUN cd /tmp && \
curl -sSL https://install.python-poetry.org > get-poetry.py && \
POETRY_HOME=/opt/poetry python get-poetry.py --version 1.8.2 && \
cd /usr/local/bin && \
ln -s /opt/poetry/bin/poetry && \
poetry config virtualenvs.create false
COPY pyproject.toml /tmp/
COPY poetry.lock /tmp/
RUN cd /tmp && poetry install --no-root --no-dev
tar -xf deck.tar.gz -C /tmp && \
mv /tmp/deck /usr/local/bin/deck127

# Final stage
FROM python:3.11-alpine3.20

WORKDIR /app

# Copy necessary files from builder stage
COPY --from=builder /usr/local/bin/kubectl /usr/local/bin/kubectl
COPY --from=builder /usr/local/bin/deck /usr/local/bin/deck
COPY --from=builder /usr/local/bin/deck127 /usr/local/bin/deck127
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages

RUN mkdir /.kube && chmod ugo+rw /.kube

# Install runtime dependencies
RUN apk add --no-cache libffi openssl curl

COPY . .

Expand Down

0 comments on commit 5f515b2

Please sign in to comment.