Skip to content

Commit

Permalink
Fix devfile to enable schema builds and go ls (#79)
Browse files Browse the repository at this point in the history
* Fix devfile to enable schema builds and go ls
* Add the vendor folder to gitIgnore
* Add the badge to open PR in Che
* Unify pre-requisite docker image between local one and devfile one
* Fix PR comments

Signed-off-by: David Festal <[email protected]>
  • Loading branch information
davidfestal authored Jun 11, 2020
1 parent e6a761a commit af56942
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 27 deletions.
22 changes: 22 additions & 0 deletions .devfile/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3-alpine
ARG OPERATOR_SDK_VERSION=v0.17.0
ENV GOROOT /usr/lib/go

RUN apk add --no-cache --update curl bash jq go \
&& pip3 install yq \
&& pip3 install jsonpatch

RUN curl -JL https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_SDK_VERSION}/operator-sdk-${OPERATOR_SDK_VERSION}-x86_64-linux-gnu -o /bin/operator-sdk && chmod a+x /bin/operator-sdk
RUN mkdir -p /home/user/go && chmod -R a+w /home/user
ENV HOME /home/user
ENV GOPATH /home/user/go

# Set permissions on /etc/passwd and /home to allow arbitrary users to write
COPY --chown=0:0 entrypoint.sh /
RUN mkdir -p /home/user && chgrp -R 0 /home && chmod -R g=u /etc/passwd /etc/group /home && chmod +x /entrypoint.sh \
&& chgrp -R 0 /usr/lib/go && chmod -R g=u /usr/lib/go

USER 10001
WORKDIR /projects
ENTRYPOINT [ "/entrypoint.sh" ]
CMD ["tail", "-f", "/dev/null"]
21 changes: 21 additions & 0 deletions .devfile/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Ensure $HOME exists when starting
if [ ! -d "${HOME}" ]; then
mkdir -p "${HOME}"
fi

# Setup $PS1 for a consistent and reasonable prompt
if [ -w "${HOME}" ] && [ ! -f "${HOME}"/.bashrc ]; then
echo "PS1='\s-\v \w \$ '" > "${HOME}"/.bashrc
fi

# Add current (arbitrary) user to /etc/passwd and /etc/group
if ! whoami &> /dev/null; then
if [ -w /etc/passwd ]; then
echo "${USER_NAME:-user}:x:$(id -u):0:${USER_NAME:-user} user:${HOME}:/bin/bash" >> /etc/passwd
echo "${USER_NAME:-user}:x:$(id -u):" >> /etc/group
fi
fi

exec "$@"
17 changes: 17 additions & 0 deletions .github/workflows/che.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# Add Che link on PRs
name: che

on:
pull_request:
types: [opened, synchronize]

jobs:
add-link:
runs-on: ubuntu-latest
steps:
- name: Eclipse Che Pull Request Check
id: che-pr-check-gh-action
uses: benoitf/che-pr-check-gh-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ tags
.vscode/*
.history
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
vendor/
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ jq ".properties.spec" "${BASE_DIR}/schemas/devworkspace-template.json" > "${BASE
cp "${BASE_DIR}/schemas/devworkspace-template-spec.json" "${BASE_DIR}/schemas/devfile.json"

transform "devfile" "${BASE_DIR}/schemas/devfile.json" ""

echo "Build of CRDs and schemas is finished"
45 changes: 38 additions & 7 deletions devfile.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
apiVersion: 1.0.0
metadata:
name: kubernetes-api
projects:
- name: kubernetes-api
source:
location: 'https://github.com/devfile/kubernetes-api.git'
type: git
clonePath: src/github.com/devfile/kubernetes-api
components:
- id: ms-vscode/go/latest
memoryLimit: 512Mi
preferences:
go.lintTool: golangci-lint
go.lintFlags: '--fast'
go.useLanguageServer: true
type: chePlugin
alias: go-plugin
env:
- value: 'off'
name: GO111MODULE
- id: redhat/vscode-yaml/latest
type: chePlugin
- mountSources: true
Expand All @@ -17,12 +26,34 @@ components:
args:
- '-c'
- >-
while [ ! -f /projects/kubernetes-api/.theia/settings.json -o
! -f /projects/.theia/settings.json ]; do echo "Waiting for the clone end" ; sleep 2; done;
sleep 2 ; echo "Updating the yaml schema bindings" ; sed -e
's:/schemas/:/kubernetes-api/schemas/:g'
/projects/kubernetes-api/.theia/settings.json >
/projects/.theia/settings.json; sleep infinity
while [ ! -f
${CHE_PROJECTS_ROOT}/src/github.com/devfile/kubernetes-api/.theia/settings.json
-o ! -f ${CHE_PROJECTS_ROOT}/.theia/settings.json ]; do echo "Waiting
for the clone end" ; sleep 2; done; sleep 2 ; echo "Updating the yaml
schema bindings" ; sed -e
's:/schemas/:/src/github.com/devfile/kubernetes-api/schemas/:g'
${CHE_PROJECTS_ROOT}/src/github.com/devfile/kubernetes-api/.theia/settings.json
> ${CHE_PROJECTS_ROOT}/.theia/settings.json; sleep infinity
- '-c'
memoryLimit: 56Mi
type: dockerimage
image: busybox
- mountSources: true
memoryLimit: 512Mi
type: dockerimage
image: 'quay.io/devfile/kubernetes-api-build-prerequisites:latest'
alias: tools
apiVersion: 1.0.0
commands:
- name: Build crds and schemas
actions:
- workdir: '${CHE_PROJECTS_ROOT}/src/github.com/devfile/kubernetes-api'
type: exec
command: ./build.sh
component: tools
- name: Fetch dependencies for Go LS
actions:
- workdir: '${CHE_PROJECTS_ROOT}/src/github.com/devfile/kubernetes-api'
type: exec
command: go mod vendor
component: tools
25 changes: 5 additions & 20 deletions docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# git ROOT directory used to mount filesystem
GIT_ROOT_DIRECTORY=$(git rev-parse --show-toplevel)
GO_MODULE=$(grep -e 'module ' ${GIT_ROOT_DIRECTORY}/go.mod | sed -e 's/module //')
WORKDIR="/home/user/go/src/${GO_MODULE}"
WORKDIR="/projects/src/${GO_MODULE}"
# Container image
IMAGE_NAME="che-incubator/devworkspace-build-prerequisites"
IMAGE_NAME="quay.io/devfile/kubernetes-api-build-prerequisites:latest"

# Operator SDK
OPERATOR_SDK_VERSION=v0.17.0
Expand All @@ -30,7 +30,7 @@ init() {

check() {
if [ $# -eq 0 ]; then
printf "%bError: %bNo script provided. Command is $ docker-run.sh <script-to-run> [optional-arguments-of-script-to-run]\n" "${RED}" "${NC}"
printf "%bError: %bNo script provided. Command is $ docker-run.sh push|<script-to-run> [optional-arguments-of-script-to-run]\n" "${RED}" "${NC}"
exit 1
fi
echo "check $1"
Expand All @@ -43,21 +43,7 @@ check() {
# Build image
build() {
printf "%bBuilding image %b${IMAGE_NAME}${NC}..." "${BOLD}" "${BLUE}"
if docker build --build-arg OPERATOR_SDK_VERSION=${OPERATOR_SDK_VERSION} -t ${IMAGE_NAME} > docker-build-log 2>&1 -<<EOF
FROM python:3-alpine
ARG OPERATOR_SDK_VERSION
ENV GOROOT /usr/lib/go
RUN apk add --no-cache --update curl bash jq go \
&& pip3 install yq \
&& pip3 install jsonpatch
RUN curl -JL https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_SDK_VERSION}/operator-sdk-${OPERATOR_SDK_VERSION}-x86_64-linux-gnu -o /bin/operator-sdk && chmod a+x /bin/operator-sdk
RUN mkdir -p /home/user/go && chmod -R a+w /home/user
ENV HOME /home/user
ENV GOPATH /home/user/go
WORKDIR ${WORKDIR}
EOF
if docker build --build-arg OPERATOR_SDK_VERSION=${OPERATOR_SDK_VERSION} -t ${IMAGE_NAME} .devfile/ > docker-build-log 2>&1
then
printf "%b[OK]%b\n" "${GREEN}" "${NC}"
rm docker-build-log
Expand All @@ -68,10 +54,9 @@ EOF
fi
}


run() {
printf "%bRunning%b $*\n" "${BOLD}" "${NC}"
if docker run --user $(id -u):$(id -g) --rm -it -v "${GIT_ROOT_DIRECTORY}":"${WORKDIR}" --entrypoint=/bin/bash ${IMAGE_NAME} -- "$@"
if docker run --user $(id -u):$(id -g) --rm -it -v "${GIT_ROOT_DIRECTORY}":"${WORKDIR}" ${IMAGE_NAME} -- bash -c "cd \"${WORKDIR}\" && $@"
then
printf "Script execution %b[OK]%b\n" "${GREEN}" "${NC}"
else
Expand Down

0 comments on commit af56942

Please sign in to comment.