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

all: support docker:// with dind #215

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ ARG ATLAS_VERSION=latest
ENV ATLAS_VERSION=${ATLAS_VERSION}
RUN curl -sSf https://atlasgo.sh | sh

FROM docker:27.3.1-cli-alpine3.20 as docker

FROM alpine:3.20
ENV ATLAS_KUBERNETES_OPERATOR=1
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=atlas /usr/local/bin/atlas /usr/local/bin
RUN chmod +x /usr/local/bin/atlas
ENV ATLAS_KUBERNETES_OPERATOR=1
COPY --from=docker /usr/local/bin/docker /usr/local/bin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not simply run apk add docker ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to version the docker cli, also need only one binary. Nothing else.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, I'm not sure if we should bundle docker-cli with the default image, or create a separated tag for dind support

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second option sounds reasonable

COPY --from=builder /workspace/manager .
USER 65532:65532
ENTRYPOINT ["/manager"]
52 changes: 52 additions & 0 deletions config/dind/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2023 The Atlas Operator Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

namespace: atlas-operator-system
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../default
patches:
- target:
kind: Deployment
namespace: system
name: controller-manager
patch: |-
- op: add
path: "/spec/template/spec/containers/0/env/-"
value:
name: DOCKER_HOST
value: "unix:///run/user/1000/docker.sock"
- op: add
path: "/spec/template/spec/containers/0/volumeMounts/-"
value:
name: dind-sock
mountPath: /run/user
- op: add
path: "/spec/template/spec/containers/-"
value:
name: dind
image: docker:27.3.1-dind-rootless
securityContext:
privileged: true
runAsGroup: 1000
runAsUser: 1000
volumeMounts:
- name: dind-sock
mountPath: /run/user
Comment on lines +40 to +47
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe replace dind with nerdctl to interactive directly with containerd

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- op: add
path: "/spec/template/spec/volumes/-"
value:
name: dind-sock
emptyDir: {}
2 changes: 2 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,7 @@ spec:
requests:
cpu: 10m
memory: 64Mi
volumeMounts: []
serviceAccountName: controller-manager
terminationGracePeriodSeconds: 10
volumes: []
1 change: 1 addition & 0 deletions skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ profiles:
paths:
- config/default
- config/sqlserver
- config/dind
- name: helm
deploy:
helm:
Expand Down
97 changes: 97 additions & 0 deletions test/e2e/testscript/schema-dind.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic postgres-credentials --from-literal=url=${DB_URL}
# Wait for the DB ready before creating the schema
kubectl wait --for=condition=ready --timeout=60s -l app=postgres pods

# Create the schema
kubectl apply -f schema.yaml
kubectl wait --for=condition=ready --timeout=360s AtlasSchema/atlasschema-postgres

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL}
cmp stdout schema.hcl
-- schema.hcl --
table "users2" {
schema = schema.public
column "id" {
null = false
type = integer
}
primary_key {
columns = [column.id]
}
}
schema "public" {
comment = "standard public schema"
}
-- schema.yaml --
apiVersion: db.atlasgo.io/v1alpha1
kind: AtlasSchema
metadata:
name: atlasschema-postgres
spec:
devURL: docker://postgres/15/dev
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is impossible before this PR.

urlFrom:
secretKeyRef:
name: postgres-credentials
key: url
schema:
sql: |
create table users2 (
id int not null,
primary key (id)
);
-- database.yaml --
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
selector:
app: postgres
ports:
- name: postgres
port: 5432
targetPort: postgres
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
selector:
matchLabels:
app: postgres
replicas: 1
template:
metadata:
labels:
app: postgres
spec:
securityContext:
runAsNonRoot: true
runAsUser: 999
containers:
- name: postgres
image: postgres:15.4
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- all
env:
- name: POSTGRES_PASSWORD
value: pass
- name: POSTGRES_USER
value: root
ports:
- containerPort: 5432
name: postgres
readinessProbe:
initialDelaySeconds: 5
periodSeconds: 2
timeoutSeconds: 1
exec:
command: [ "pg_isready" ]
Loading