Skip to content

Commit 6f9d55f

Browse files
committed
add steps for creating compatible image and template
1 parent aa8add4 commit 6f9d55f

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

docs/install/openshift.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,115 @@ helm install coder coder-v2/coder \
146146
--namespace coder \
147147
--values values.yaml
148148
```
149+
150+
### 7. Create an OpenShift-compatible image
151+
152+
While the deployment is spinning up, we will need to create some images that
153+
are compatible with OpenShift. These images can then be run without modifying
154+
the Security Context Constraints (SCCs) in OpenShift.
155+
156+
1. Determine the UID range for the project:
157+
158+
```console
159+
oc get project coder -o json | jq -r '.metadata.annotations'
160+
{
161+
"openshift.io/description": "",
162+
"openshift.io/display-name": "coder",
163+
"openshift.io/requester": "kube:admin",
164+
"openshift.io/sa.scc.mcs": "s0:c26,c15",
165+
"openshift.io/sa.scc.supplemental-groups": "1000680000/10000",
166+
"openshift.io/sa.scc.uid-range": "1000680000/10000"
167+
}
168+
```
169+
170+
Note the `uid-range` and `supplemental-groups`. In this case, the project `coder`
171+
has been allocated 10,000 UIDs starting at 1000680000, and 10,000 GIDs starting
172+
at 1000680000. In this example, we will pick UID and GID 1000680000.
173+
174+
1. Create a `BuildConfig` referencing the source image you want to customize.
175+
This will automatically kick off a `Build` that will remain pending until step 3.
176+
177+
> For more information, please consult the [OpenShift Documentation](https://docs.openshift.com/container-platform/4.12/cicd/builds/understanding-buildconfigs.html).
178+
179+
```console
180+
oc create -f - <<EOF
181+
kind: BuildConfig
182+
apiVersion: build.openshift.io/v1
183+
metadata:
184+
name: enterprise-base
185+
namespace: coder
186+
spec:
187+
output:
188+
to:
189+
kind: ImageStreamTag
190+
name: 'enterprise-base:latest'
191+
strategy:
192+
type: Docker
193+
dockerStrategy:
194+
imageOptimizationPolicy: SkipLayers
195+
source:
196+
type: Dockerfile
197+
dockerfile: |
198+
# Specify the source image.
199+
FROM docker.io/codercom/enterprise-base:ubuntu
200+
201+
# Switch to root
202+
USER root
203+
204+
# As root:
205+
# 1) Remove the original coder user with UID 1000
206+
# 2) Add a coder group with an allowed UID
207+
# 3) Add a coder user as a member of the above group
208+
# 4) Fix ownership on the user's home directory
209+
RUN userdel coder && \
210+
groupadd coder -g 1000680000 && \
211+
useradd -l -u 1000680000 coder -g 1000680000 && \
212+
chown -R coder:coder /home/coder
213+
214+
# Go back to the user 'coder'
215+
USER coder
216+
triggers:
217+
- type: ConfigChange
218+
runPolicy: Serial
219+
EOF
220+
```
221+
222+
223+
1. Create an `ImageStream` as a target for the previous step:
224+
225+
```console
226+
oc create imagestream enterprise-base
227+
```
228+
229+
The `Build` created in the previous step should now begin.
230+
Once completed, you should see output similar to the following:
231+
232+
```console
233+
oc get imagestreamtag
234+
NAME IMAGE REFERENCE UPDATED
235+
enterprise-base:latest image-registry.openshift-image-registry.svc:5000/coder/enterprise-base@sha256:1dbbe4ee11be9218e1e4741264135a4f57501fe592d94d20db6bfe11692accd1 55 minutes ago
236+
```
237+
238+
### 8. Create an OpenShift-compatible template
239+
240+
Start from the default "Kubernetes" template:
241+
242+
```console
243+
echo kubernetes | coderv2 templates init ./openshift-k8s
244+
cd ./openshift-k8s
245+
```
246+
247+
Edit `main.tf` and update the following fields of the Kubernetes pod resource:
248+
249+
- `spec.security_context`: remove this field.
250+
- `spec.container.image`: update this field to the newly built image hosted
251+
on the OpenShift image registry from the previous step.
252+
- `spec.container.security_context`: remove this field.
253+
254+
Finally, create the template:
255+
256+
```console
257+
coder template create kubernetes -d .
258+
```
259+
260+
This template should be ready to use straight away.

0 commit comments

Comments
 (0)