Skip to content

Commit d67b20c

Browse files
committed
all: support docker:// with Dind
1 parent 5c3e5f3 commit d67b20c

File tree

5 files changed

+157
-3
lines changed

5 files changed

+157
-3
lines changed

Dockerfile

+5-3
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ ARG ATLAS_VERSION=latest
4646
ENV ATLAS_VERSION=${ATLAS_VERSION}
4747
RUN curl -sSf https://atlasgo.sh | sh
4848

49+
FROM docker:27.3.1-cli-alpine3.20 as docker
50+
4951
FROM alpine:3.20
52+
ENV ATLAS_KUBERNETES_OPERATOR=1
5053
WORKDIR /
51-
COPY --from=builder /workspace/manager .
5254
COPY --from=atlas /usr/local/bin/atlas /usr/local/bin
53-
RUN chmod +x /usr/local/bin/atlas
54-
ENV ATLAS_KUBERNETES_OPERATOR=1
55+
COPY --from=docker /usr/local/bin/docker /usr/local/bin
56+
COPY --from=builder /workspace/manager .
5557
USER 65532:65532
5658
ENTRYPOINT ["/manager"]

config/dind/kustomization.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2023 The Atlas Operator Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
namespace: atlas-operator-system
16+
apiVersion: kustomize.config.k8s.io/v1beta1
17+
kind: Kustomization
18+
resources:
19+
- ../default
20+
patches:
21+
- target:
22+
kind: Deployment
23+
namespace: system
24+
name: controller-manager
25+
patch: |-
26+
- op: add
27+
path: "/spec/template/spec/containers/0/env/-"
28+
value:
29+
name: DOCKER_HOST
30+
value: "unix:///run/user/1000/docker.sock"
31+
- op: add
32+
path: "/spec/template/spec/containers/0/volumeMounts/-"
33+
value:
34+
name: dind-sock
35+
mountPath: /run/user
36+
- op: add
37+
path: "/spec/template/spec/containers/-"
38+
value:
39+
name: dind
40+
image: docker:27.3.1-dind-rootless
41+
securityContext:
42+
privileged: true
43+
runAsGroup: 1000
44+
runAsUser: 1000
45+
volumeMounts:
46+
- name: dind-sock
47+
mountPath: /run/user
48+
- op: add
49+
path: "/spec/template/spec/volumes/-"
50+
value:
51+
name: dind-sock
52+
emptyDir: {}

config/manager/manager.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,7 @@ spec:
114114
requests:
115115
cpu: 10m
116116
memory: 64Mi
117+
volumeMounts: []
117118
serviceAccountName: controller-manager
118119
terminationGracePeriodSeconds: 10
120+
volumes: []

skaffold.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ profiles:
3030
paths:
3131
- config/default
3232
- config/sqlserver
33+
- config/dind
3334
- name: helm
3435
deploy:
3536
helm:

test/e2e/testscript/schema-dind.txtar

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
2+
kubectl apply -f database.yaml
3+
kubectl create secret generic postgres-credentials --from-literal=url=${DB_URL}
4+
# Wait for the DB ready before creating the schema
5+
kubectl wait --for=condition=ready --timeout=60s -l app=postgres pods
6+
7+
# Create the schema
8+
kubectl apply -f schema.yaml
9+
kubectl wait --for=condition=ready --timeout=360s AtlasSchema/atlasschema-postgres
10+
11+
# Inspect the schema to ensure it's correct
12+
atlas schema inspect -u ${DB_URL}
13+
cmp stdout schema.hcl
14+
-- schema.hcl --
15+
table "users2" {
16+
schema = schema.public
17+
column "id" {
18+
null = false
19+
type = integer
20+
}
21+
primary_key {
22+
columns = [column.id]
23+
}
24+
}
25+
schema "public" {
26+
comment = "standard public schema"
27+
}
28+
-- schema.yaml --
29+
apiVersion: db.atlasgo.io/v1alpha1
30+
kind: AtlasSchema
31+
metadata:
32+
name: atlasschema-postgres
33+
spec:
34+
devURL: docker://postgres/15/dev
35+
urlFrom:
36+
secretKeyRef:
37+
name: postgres-credentials
38+
key: url
39+
schema:
40+
sql: |
41+
create table users2 (
42+
id int not null,
43+
primary key (id)
44+
);
45+
-- database.yaml --
46+
apiVersion: v1
47+
kind: Service
48+
metadata:
49+
name: postgres
50+
spec:
51+
selector:
52+
app: postgres
53+
ports:
54+
- name: postgres
55+
port: 5432
56+
targetPort: postgres
57+
type: ClusterIP
58+
---
59+
apiVersion: apps/v1
60+
kind: Deployment
61+
metadata:
62+
name: postgres
63+
spec:
64+
selector:
65+
matchLabels:
66+
app: postgres
67+
replicas: 1
68+
template:
69+
metadata:
70+
labels:
71+
app: postgres
72+
spec:
73+
securityContext:
74+
runAsNonRoot: true
75+
runAsUser: 999
76+
containers:
77+
- name: postgres
78+
image: postgres:15.4
79+
securityContext:
80+
allowPrivilegeEscalation: false
81+
capabilities:
82+
drop:
83+
- all
84+
env:
85+
- name: POSTGRES_PASSWORD
86+
value: pass
87+
- name: POSTGRES_USER
88+
value: root
89+
ports:
90+
- containerPort: 5432
91+
name: postgres
92+
readinessProbe:
93+
initialDelaySeconds: 5
94+
periodSeconds: 2
95+
timeoutSeconds: 1
96+
exec:
97+
command: [ "pg_isready" ]

0 commit comments

Comments
 (0)