Skip to content

Commit

Permalink
chore: refactor docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Nov 17, 2024
1 parent de30620 commit cc9ee4e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 19 deletions.
31 changes: 20 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
FROM cgr.dev/chainguard/wolfi-base AS builder
FROM cgr.dev/chainguard/wolfi-base AS base

RUN apk add --no-cache go npm make git pnpm curl
RUN apk add --no-cache go make git npm pnpm

FROM base AS bin
WORKDIR /app
COPY . .
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/.cache/uv \
--mount=type=cache,target=/root/go/pkg/mod \
make in-docker-build
make all

FROM base AS tools
RUN apk add --no-cache curl python-3.13 py3.13-pip
WORKDIR /app
COPY . .
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/.cache/uv \
--mount=type=cache,target=/root/go/pkg/mod \
UV_LINK_MODE=copy BIN_DIR=/bin make package-tools

FROM cgr.dev/chainguard/wolfi-base AS final
RUN apk add --no-cache git python-3.13 py3.13-pip openssh-server npm bash tini procps libreoffice
Expand All @@ -16,13 +29,6 @@ RUN sed -E 's/^#(PermitRootLogin)no/\1yes/' /etc/ssh/sshd_config -i
RUN ssh-keygen -A
RUN mkdir /run/sshd && /usr/sbin/sshd
COPY encryption.yaml /
COPY --from=builder /app/bin/otto8 /bin/
COPY --link --from=builder /app/otto8-tools /otto8-tools
RUN <<EOF
for i in $(find /otto8-tools/[^k]* -name requirements.txt -exec cat {} \; -exec echo \; | sort -u); do
pip install "$i"
done
EOF
COPY --chmod=0755 <<EOF /bin/run.sh
#!/bin/bash
set -e
Expand All @@ -46,9 +52,12 @@ VERSIONS
exec tini -- otto8 server
EOF

COPY --link --from=tools /app/otto8-tools /otto8-tools
COPY --from=bin /app/bin/otto8 /bin/

EXPOSE 22
# libreoffice executables
ENV PATH=$PATH:/usr/lib/libreoffice/program
ENV PATH=/otto8-tools/venv/bin:$PATH:/usr/lib/libreoffice/program
ENV HOME=/data
ENV XDG_CACHE_HOME=/data/cache
ENV GPTSCRIPT_SYSTEM_TOOLS_DIR=/otto8-tools/
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ lint-admin:
package-tools:
./tools/package-tools.sh

in-docker-build: all package-tools

no-changes:
@if [ -n "$$(git status --porcelain)" ]; then \
git status --porcelain; \
Expand Down
41 changes: 41 additions & 0 deletions apiclient/emailreceiver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package apiclient

import (
"context"
"fmt"
"net/http"
"sort"

"github.com/otto8-ai/otto8/apiclient/types"
)

func (c *Client) ListEmailReceivers(ctx context.Context) (result types.EmailReceiverList, _ error) {
defer func() {
sort.Slice(result.Items, func(i, j int) bool {
return result.Items[i].Metadata.Created.Time.Before(result.Items[j].Metadata.Created.Time)
})
}()

_, resp, err := c.doRequest(ctx, http.MethodGet, "/email-receivers", nil)
if err != nil {
return
}
defer resp.Body.Close()

_, err = toObject(resp, &result)
if err != nil {
return result, err
}

return result, nil
}

func (c *Client) DeleteEmailReceiver(ctx context.Context, id string) error {
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/email-receivers/"+id), nil)
if err != nil {
return err
}
defer resp.Body.Close()

return nil
}
22 changes: 17 additions & 5 deletions pkg/alias/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,23 @@ import (
)

func Get(ctx context.Context, c kclient.Client, obj v1.Aliasable, namespace string, name string) error {
errLookup := c.Get(ctx, router.Key(namespace, name), obj.(kclient.Object))
if kclient.IgnoreNotFound(errLookup) != nil {
return errLookup
} else if errLookup == nil {
return nil
var errLookup error
if namespace == "" {
gvk, err := c.GroupVersionKindFor(obj.(kclient.Object))
if err != nil {
return err
}
errLookup = apierrors.NewNotFound(schema.GroupResource{
Group: gvk.Group,
Resource: gvk.Kind,
}, name)
} else {
errLookup = c.Get(ctx, router.Key(namespace, name), obj.(kclient.Object))
if kclient.IgnoreNotFound(errLookup) != nil {
return errLookup
} else if errLookup == nil {
return nil
}
}

gvk, err := c.GroupVersionKindFor(obj.(kclient.Object))
Expand Down
19 changes: 18 additions & 1 deletion tools/package-tools.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
set -e -x -o pipefail

BIN_DIR=${BIN_DIR:-./bin}

cd $(dirname $0)/..

if [ ! -e otto8-tools ]; then
Expand Down Expand Up @@ -44,4 +46,19 @@ if [ ! -e aws-encryption-provider ]; then
fi

cd aws-encryption-provider
go build -o /bin/aws-encryption-provider cmd/server/main.go
go build -o ${BIN_DIR}/aws-encryption-provider cmd/server/main.go

cd ../..

if ! command -v uv; then
pip install uv
fi

if [ ! -e otto8-tools/venv ]; then
uv venv otto8-tools/venv
fi

source otto8-tools/venv/bin/activate

find otto8-tools -name requirements.txt -exec cat {} \; -exec echo \; | sort -u > requirements.txt
uv pip install -r requirements.txt

0 comments on commit cc9ee4e

Please sign in to comment.