Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
feat(Dockerfile): install kubectl and istioctl
Browse files Browse the repository at this point in the history
  • Loading branch information
Constantine Karnaukhov committed Sep 19, 2018
1 parent c42fd8e commit 898e07c
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 60 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[**.{js,ts,jsx,tsx,less,css,sass,scss,json,yml,yaml}]
indent_size = 2
indent_style = space
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Numerous always-ignore extensions
*.diff
*.err
*.orig
*.log*
*.rej
*.swo
*.swp
*.zip
*.vi
*~
*.lock
!**/yarn.lock
!**/composer.lock

# Dotenv
.env
.env.*
!.env.example

# OS or Editor folders
.DS_Store
._*
Thumbs.db
.cache
.project
.settings
.tmproj
*.esproj
nbproject
*.sublime-project
*.sublime-workspace
.idea
*.komodoproject
.komodotools
.atom
.vscode
.directory
.sql
47 changes: 34 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
FROM frolvlad/alpine-glibc:latest

MAINTAINER Daniel Widerin <[email protected]>
LABEL maintainer="Constantine Karnaukhov <[email protected]>"

# Install dependencies
ENV BUILD_DEPS='tar gzip' \
RUN_DEPS='curl ca-certificates gettext'

RUN apk --no-cache add $BUILD_DEPS $RUN_DEPS

# Install kubectl
ENV KUBECTL_VERSION=v1.11.3

RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl && \
chmod +x ./kubectl && \
mv ./kubectl /usr/local/bin/

# Install OpenShift CLI
ENV OC_VERSION=v3.10.0 \
OC_TAG_SHA=dd10d17 \
BUILD_DEPS='tar gzip' \
RUN_DEPS='curl ca-certificates gettext'

RUN apk --no-cache add $BUILD_DEPS $RUN_DEPS && \
curl -sLo /tmp/oc.tar.gz https://github.com/openshift/origin/releases/download/${OC_VERSION}/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit.tar.gz && \
tar xzvf /tmp/oc.tar.gz -C /tmp/ && \
mv /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit/oc /usr/local/bin/ && \
rm -rf /tmp/oc.tar.gz /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit && \
apk del $BUILD_DEPS

CMD ["/usr/local/bin/oc"]
OC_TAG_SHA=dd10d17

RUN curl -sLo /tmp/oc.tar.gz https://github.com/openshift/origin/releases/download/${OC_VERSION}/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit.tar.gz && \
tar xzvf /tmp/oc.tar.gz -C /tmp/ && \
mv /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit/oc /usr/local/bin/ && \
rm -rf /tmp/oc.tar.gz /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit

# Install istioctl
ENV ISTIO_VERSION=1.0.2

RUN curl -sLo /tmp/istio.tar.gz https://github.com/istio/istio/releases/download/${ISTIO_VERSION}/istio-${ISTIO_VERSION}-linux.tar.gz && \
tar xzvf /tmp/istio.tar.gz -C /tmp/ && \
mv /tmp/istio-${ISTIO_VERSION}/bin/istioctl /usr/local/bin/ && \
rm -rf /tmp/istio.tar.gz /tmp/istio-${ISTIO_VERSION}

# Clean cache
RUN apk del $BUILD_DEPS

CMD ["sh"]
102 changes: 55 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
OpenShift CLI for CI/CD
=======================
# k8s-deploy-tools

This [Openshift command line tool](https://docs.openshift.com/enterprise/3.0/cli_reference/get_started_cli.html) docker
image ships `oc` and includes `gettext` so you can use `envsubst` to substitute
environment variables in your CI/CD pipeline, for example using in
[Jenkins](https://jenkins.io/) or a job in [GitLab CI .gitlab-ci.yml file](https://docs.gitlab.com/ce/ci/yaml/README.html#gitlab-ci-yml).
CI/CD deployment tools for Kubernetes

Examples
--------
## Docker Image

This alpine-based docker image contains next tools:

- [`kubectl`](https://kubernetes.io/docs/reference/kubectl/kubectl/) - Kubernetes CLI
- [`oc`](https://docs.openshift.com/enterprise/3.0/cli_reference/get_started_cli.html) - OpenShift CLI
- [`istioctl`](https://istio.io/docs/reference/commands/istioctl/) - Istio cli
- `gettext` - so you can use `envsubst` to substitute environment variables in your CI/CD pipeline

## Examples

Why should I use `envsubst`? You should never put secrets into your version
control, so you might want to keep them in secret variables in your CI/CD
Expand All @@ -21,49 +25,53 @@ Below I'll show an example of [GitLab CI variables set in the build environment]

Your `app.yaml` could look similar the one below:

$ cat app.yaml
...
- apiVersion: v1
kind: DeploymentConfig
metadata:
labels:
app: ${CI_PROJECT_NAME}
name: sample
spec:
replicas: 1
selector:
app: ${CI_PROJECT_NAME}
deployment: ${CI_BUILD_REF_SLUG}
...
```yaml
...
- apiVersion: v1
kind: DeploymentConfig
metadata:
labels:
app: ${CI_PROJECT_NAME}
name: sample
spec:
replicas: 1
selector:
app: ${CI_PROJECT_NAME}
deployment: ${CI_BUILD_REF_SLUG}
...
```

After `cat app.yaml | envsubst > app.yaml` you'll notice the variables have
been replaced with their actual values:

$ cat app.yaml
...
- apiVersion: v1
kind: DeploymentConfig
metadata:
labels:
app: my_awesome_project
name: sample
spec:
replicas: 1
selector:
app: my_awesome_project
deployment: f1234d
...
```yaml
...
- apiVersion: v1
kind: DeploymentConfig
metadata:
labels:
app: my_awesome_project
name: sample
spec:
replicas: 1
selector:
app: my_awesome_project
deployment: f1234d
...
```

GitLab CI example
-----------------
## GitLab CI example

Below a sample job in an `.gitlab-ci.yml` file, please note that OpenShift does
not allow `_` in project names:
Below a sample job in an `.gitlab-ci.yml` file:

deploy:
image: widerin/openshift-cli
stage: deploy
script:
- oc login "$OPENSHIFT_SERVER" --token="$OPENSHIFT_TOKEN"
- cat app.yaml | envsubst > app.yaml
- oc replace -f app.yaml -n ${CI_PROJECT_NAME/_/}
```yaml
deploy:
image: spaceonfire/k8s-deploy-tools
stage: deploy
before_script:
- oc login "$KUBE_URL" --token="$KUBE_TOKEN" --insecure-skip-tls-verify
- oc project "$KUBE_NAMESPACE" 2> /dev/null || oc new-project "$KUBE_NAMESPACE"
script:
- cat app.yaml | envsubst > app.yaml
- oc apply -f app.yaml
```

0 comments on commit 898e07c

Please sign in to comment.