diff --git a/.devfile/Dockerfile b/.devfile/Dockerfile new file mode 100644 index 000000000..5c097bb56 --- /dev/null +++ b/.devfile/Dockerfile @@ -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"] diff --git a/.devfile/entrypoint.sh b/.devfile/entrypoint.sh new file mode 100644 index 000000000..3c79715c3 --- /dev/null +++ b/.devfile/entrypoint.sh @@ -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 "$@" diff --git a/.github/workflows/che.yaml b/.github/workflows/che.yaml new file mode 100644 index 000000000..6f3ae6526 --- /dev/null +++ b/.github/workflows/che.yaml @@ -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 }} diff --git a/.gitignore b/.gitignore index 7c504700d..3f21a15e9 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,4 @@ tags .vscode/* .history # End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode +vendor/ diff --git a/build.sh b/build.sh index 27735ac8e..b31f8d7dd 100755 --- a/build.sh +++ b/build.sh @@ -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" diff --git a/devfile.yaml b/devfile.yaml index 70d3e3214..e8d93151c 100644 --- a/devfile.yaml +++ b/devfile.yaml @@ -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 @@ -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 diff --git a/docker-run.sh b/docker-run.sh index 1327dc09f..263c6494c 100755 --- a/docker-run.sh +++ b/docker-run.sh @@ -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 @@ -30,7 +30,7 @@ init() { check() { if [ $# -eq 0 ]; then - printf "%bError: %bNo script provided. Command is $ docker-run.sh [optional-arguments-of-script-to-run]\n" "${RED}" "${NC}" + printf "%bError: %bNo script provided. Command is $ docker-run.sh push| [optional-arguments-of-script-to-run]\n" "${RED}" "${NC}" exit 1 fi echo "check $1" @@ -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 -< docker-build-log 2>&1 then printf "%b[OK]%b\n" "${GREEN}" "${NC}" rm docker-build-log @@ -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