Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add k8s (python kubernetes) support #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ jobs:
DOCKER_TAG_AZURE="${VERSION}-azure"
DOCKER_TAG_AWS="${VERSION}-aws"
DOCKER_TAG_AWSK8S="${VERSION}-awsk8s"
DOCKER_TAG_K8S="${VERSION}-k8s"
else
DOCKER_TAG_BASE="${VERSION}-${GIT_SLUG}"
DOCKER_TAG_TOOLS="${VERSION}-tools-${GIT_SLUG}"
DOCKER_TAG_INFRA="${VERSION}-infra-${GIT_SLUG}"
DOCKER_TAG_AZURE="${VERSION}-azure-${GIT_SLUG}"
DOCKER_TAG_AWS="${VERSION}-aws-${GIT_SLUG}"
DOCKER_TAG_AWSK8S="${VERSION}-awsk8s-${GIT_SLUG}"
DOCKER_TAG_K8S="${VERSION}-k8s-${GIT_SLUG}"
fi

# Output
Expand All @@ -96,6 +98,7 @@ jobs:
echo "DOCKER_TAG_AZURE=${DOCKER_TAG_AZURE}"
echo "DOCKER_TAG_AWS=${DOCKER_TAG_AWS}"
echo "DOCKER_TAG_AWSK8S=${DOCKER_TAG_AWSK8S}"
echo "DOCKER_TAG_K8S=${DOCKER_TAG_K8S}"

# Export variable
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
Expand All @@ -107,6 +110,7 @@ jobs:
echo "DOCKER_TAG_AZURE=${DOCKER_TAG_AZURE}" >> ${GITHUB_ENV}
echo "DOCKER_TAG_AWS=${DOCKER_TAG_AWS}" >> ${GITHUB_ENV}
echo "DOCKER_TAG_AWSK8S=${DOCKER_TAG_AWSK8S}" >> ${GITHUB_ENV}
echo "DOCKER_TAG_K8S=${DOCKER_TAG_K8S}" >> ${GITHUB_ENV}
env:
VERSION: ${{ matrix.version }}

Expand Down Expand Up @@ -221,6 +225,22 @@ jobs:
VERSION: ${{ matrix.version }}


# ------------------------------------------------------------
# K8s
# ------------------------------------------------------------
- name: Build Ansible K8s
run: |
scripts/retry make build ANSIBLE=${VERSION} FLAVOUR=k8s
env:
VERSION: ${{ matrix.version }}

- name: Test Ansible K8s
run: |
scripts/retry make test ANSIBLE=${VERSION} FLAVOUR=k8s
env:
VERSION: ${{ matrix.version }}


# ------------------------------------------------------------
# Deploy
# ------------------------------------------------------------
Expand All @@ -236,6 +256,7 @@ jobs:
echo "DOCKER_TAG_AZURE=${DOCKER_TAG_AZURE}"
echo "DOCKER_TAG_AWS=${DOCKER_TAG_AWS}"
echo "DOCKER_TAG_AWSK8S=${DOCKER_TAG_AWSK8S}"
echo "DOCKER_TAG_K8S=${DOCKER_TAG_K8S}"

# Tag image
scripts/retry make tag ANSIBLE=${VERSION} FLAVOUR=base TAG=${DOCKER_TAG_BASE}
Expand All @@ -244,6 +265,7 @@ jobs:
scripts/retry make tag ANSIBLE=${VERSION} FLAVOUR=azure TAG=${DOCKER_TAG_AZURE}
scripts/retry make tag ANSIBLE=${VERSION} FLAVOUR=aws TAG=${DOCKER_TAG_AWS}
scripts/retry make tag ANSIBLE=${VERSION} FLAVOUR=awsk8s TAG=${DOCKER_TAG_AWSK8S}
scripts/retry make tag ANSIBLE=${VERSION} FLAVOUR=k8s TAG=${DOCKER_TAG_K8S}
docker images | grep cytopia/ansible

# Login
Expand All @@ -256,6 +278,7 @@ jobs:
scripts/retry make push TAG=${DOCKER_TAG_AZURE}
scripts/retry make push TAG=${DOCKER_TAG_AWS}
scripts/retry make push TAG=${DOCKER_TAG_AWSK8S}
scripts/retry make push TAG=${DOCKER_TAG_K8S}
env:
VERSION: ${{ matrix.version }}
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ jobs:
DOCKER_TAG_AZURE="${VERSION}-azure"
DOCKER_TAG_AWS="${VERSION}-aws"
DOCKER_TAG_AWSK8S="${VERSION}-awsk8s"
DOCKER_TAG_K8S="${VERSION}-k8s"
else
DOCKER_TAG_BASE="${VERSION}-${GIT_SLUG}"
DOCKER_TAG_TOOLS="${VERSION}-tools-${GIT_SLUG}"
DOCKER_TAG_INFRA="${VERSION}-infra-${GIT_SLUG}"
DOCKER_TAG_AZURE="${VERSION}-azure-${GIT_SLUG}"
DOCKER_TAG_AWS="${VERSION}-aws-${GIT_SLUG}"
DOCKER_TAG_AWSK8S="${VERSION}-awsk8s-${GIT_SLUG}"
DOCKER_TAG_K8S="${VERSION}-k8s-${GIT_SLUG}"
fi

# Output
Expand All @@ -95,6 +97,7 @@ jobs:
echo "DOCKER_TAG_AZURE=${DOCKER_TAG_AZURE}"
echo "DOCKER_TAG_AWS=${DOCKER_TAG_AWS}"
echo "DOCKER_TAG_AWSK8S=${DOCKER_TAG_AWSK8S}"
echo "DOCKER_TAG_K8S=${DOCKER_TAG_K8S}"

# Export variable
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
Expand All @@ -106,6 +109,7 @@ jobs:
echo "DOCKER_TAG_AZURE=${DOCKER_TAG_AZURE}" >> ${GITHUB_ENV}
echo "DOCKER_TAG_AWS=${DOCKER_TAG_AWS}" >> ${GITHUB_ENV}
echo "DOCKER_TAG_AWSK8S=${DOCKER_TAG_AWSK8S}" >> ${GITHUB_ENV}
echo "DOCKER_TAG_K8S=${DOCKER_TAG_K8S}" >> ${GITHUB_ENV}
env:
VERSION: ${{ matrix.version }}

Expand Down Expand Up @@ -220,6 +224,22 @@ jobs:
VERSION: ${{ matrix.version }}


# ------------------------------------------------------------
# K8s
# ------------------------------------------------------------
- name: Build Ansible K8s
run: |
scripts/retry make build ANSIBLE=${VERSION} FLAVOUR=k8s
env:
VERSION: ${{ matrix.version }}

- name: Test Ansible K8s
run: |
scripts/retry make test ANSIBLE=${VERSION} FLAVOUR=k8s
env:
VERSION: ${{ matrix.version }}


# ------------------------------------------------------------
# Deploy
# ------------------------------------------------------------
Expand All @@ -235,6 +255,7 @@ jobs:
echo "DOCKER_TAG_AZURE=${DOCKER_TAG_AZURE}"
echo "DOCKER_TAG_AWS=${DOCKER_TAG_AWS}"
echo "DOCKER_TAG_AWSK8S=${DOCKER_TAG_AWSK8S}"
echo "DOCKER_TAG_K8S=${DOCKER_TAG_K8S}"

# Tag image
scripts/retry make tag ANSIBLE=${VERSION} FLAVOUR=base TAG=${DOCKER_TAG_BASE}
Expand All @@ -243,6 +264,7 @@ jobs:
scripts/retry make tag ANSIBLE=${VERSION} FLAVOUR=azure TAG=${DOCKER_TAG_AZURE}
scripts/retry make tag ANSIBLE=${VERSION} FLAVOUR=aws TAG=${DOCKER_TAG_AWS}
scripts/retry make tag ANSIBLE=${VERSION} FLAVOUR=awsk8s TAG=${DOCKER_TAG_AWSK8S}
scripts/retry make tag ANSIBLE=${VERSION} FLAVOUR=k8s TAG=${DOCKER_TAG_K8S}
docker images | grep cytopia/ansible

# Login
Expand All @@ -255,6 +277,7 @@ jobs:
scripts/retry make push TAG=${DOCKER_TAG_AZURE}
scripts/retry make push TAG=${DOCKER_TAG_AWS}
scripts/retry make push TAG=${DOCKER_TAG_AWSK8S}
scripts/retry make push TAG=${DOCKER_TAG_K8S}
env:
VERSION: ${{ matrix.version }}
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
Expand Down
43 changes: 43 additions & 0 deletions Dockerfiles/Dockerfile-k8s
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
ARG VERSION

# --------------------------------------------------------------------------------------------------
# Builder Image
# --------------------------------------------------------------------------------------------------
# See ./builder for this image
FROM cytopia/ansible-builder as builder

# Python packages (copied to final image)
RUN set -eux \
&& pip3 install --no-cache-dir --no-compile \
--ignore-installed PyYAML \
docker \
kubernetes \
&& find /usr/lib/ -name '__pycache__' -print0 | xargs -0 -n1 rm -rf \
&& find /usr/lib/ -name '*.pyc' -print0 | xargs -0 -n1 rm -rf


# --------------------------------------------------------------------------------------------------
# Final Image
# --------------------------------------------------------------------------------------------------
FROM cytopia/ansible:${VERSION}-tools as production
ARG VERSION
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
#LABEL "org.opencontainers.image.created"=""
#LABEL "org.opencontainers.image.version"=""
#LABEL "org.opencontainers.image.revision"=""
LABEL "maintainer"="cytopia <[email protected]>"
LABEL "org.opencontainers.image.authors"="cytopia <[email protected]>"
LABEL "org.opencontainers.image.vendor"="cytopia"
LABEL "org.opencontainers.image.licenses"="MIT"
LABEL "org.opencontainers.image.url"="https://github.com/cytopia/docker-ansible"
LABEL "org.opencontainers.image.documentation"="https://github.com/cytopia/docker-ansible"
LABEL "org.opencontainers.image.source"="https://github.com/cytopia/docker-ansible"
LABEL "org.opencontainers.image.ref.name"="Ansible ${VERSION} k8s"
LABEL "org.opencontainers.image.title"="Ansible ${VERSION} k8s"
LABEL "org.opencontainers.image.description"="Ansible ${VERSION} k8s"

COPY --from=builder /usr/lib/python3.8/site-packages/ /usr/lib/python3.8/site-packages/

WORKDIR /data
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/bin/bash"]
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ help:
@echo " make build ANSIBLE=2.3 FLAVOUR=awsk8s"
@echo " make build ANSIBLE=2.3 FLAVOUR=awshelm HELM=2.11"
@echo " make build ANSIBLE=2.3 FLAVOUR=awskops KOPS=1.15"
@echo " make build ANSIBLE=2.3 FLAVOUR=k8s"
@echo
@echo "--------------------------------------------------------------------------------"
@echo " Test Targets"
Expand All @@ -67,6 +68,7 @@ help:
@echo " make test ANSIBLE=2.3 FLAVOUR=awsk8s"
@echo " make test ANSIBLE=2.3 FLAVOUR=awshelm HELM=2.11"
@echo " make test ANSIBLE=2.3 FLAVOUR=awskops KOPS=1.15"
@echo " make test ANSIBLE=2.3 FLAVOUR=k8s"
@echo
@echo "--------------------------------------------------------------------------------"
@echo " Tagging Target"
Expand All @@ -82,6 +84,7 @@ help:
@echo " make tag ANSIBLE=2.3 FLAVOUR=awsk8s TAG=2.3-awsk8s-mysuffix"
@echo " make tag ANSIBLE=2.3 FLAVOUR=awshelm HELM=2.11 TAG=2.3-awshelm-mysuffix"
@echo " make tag ANSIBLE=2.3 FLAVOUR=awskops KOPS=1.15 TAG=2.3-awskops-mysuffix"
@echo " make tag ANSIBLE=2.3 FLAVOUR=k8s TAG=2.3-k8s-mysuffix"
@echo
@echo "--------------------------------------------------------------------------------"
@echo " MISC Targets"
Expand Down Expand Up @@ -278,6 +281,7 @@ test-python-libs:
REQUIRED_AWSK8S="openshift"; \
REQUIRED_AWSKOPS=""; \
REQUIRED_AWSHELM=""; \
REQUIRED_K8S="docker kubernetes"; \
\
\
if [ "$(FLAVOUR)" = "base" ]; then \
Expand Down Expand Up @@ -397,6 +401,14 @@ test-python-libs:
exit 1; \
fi; \
done; \
for lib in $${REQUIRED_K8S}; do \
if ! echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] unwanted lib not available: $${lib}"; \
else \
echo "[FAILED] unwanted lib available: $${lib}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(FLAVOUR)" = "awshelm" ]; then \
for lib in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AWS} $${REQUIRED_AWSK8S} $${REQUIRED_AWSHELM} ); do \
Expand All @@ -407,6 +419,24 @@ test-python-libs:
exit 1; \
fi; \
done; \
for lib in $${REQUIRED_K8S}; do \
if ! echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] unwanted lib not available: $${lib}"; \
else \
echo "[FAILED] unwanted lib available: $${lib}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(FLAVOUR)" = "k8s" ]; then \
for lib in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_K8S} ); do \
if echo "$${LIBS}" | grep -E "^$${lib}" >/dev/null; then \
echo "[OK] required lib available: $${lib}"; \
else \
echo "[FAILED] required lib not available: $${lib}"; \
exit 1; \
fi; \
done; \
\
fi; \
echo "[SUCCESS]"; \
Expand Down Expand Up @@ -435,6 +465,7 @@ test-binaries:
REQUIRED_AWSK8S="kubectl oc"; \
REQUIRED_AWSKOPS="kops"; \
REQUIRED_AWSHELM="helm"; \
REQUIRED_K8S=""; \
\
\
if [ "$(FLAVOUR)" = "base" ]; then \
Expand Down Expand Up @@ -554,6 +585,14 @@ test-binaries:
exit 1; \
fi; \
done; \
for bin in $${REQUIRED_K8S}; do \
if ! echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] unwanted bin not available: $${bin}"; \
else \
echo "[FAILED] unwanted bin available: $${bin}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(FLAVOUR)" = "awshelm" ]; then \
for bin in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_AWS} $${REQUIRED_AWSK8S} $${REQUIRED_AWSHELM} ); do \
Expand All @@ -564,6 +603,24 @@ test-binaries:
exit 1; \
fi; \
done; \
for bin in $${REQUIRED_K8S}; do \
if ! echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] unwanted bin not available: $${bin}"; \
else \
echo "[FAILED] unwanted bin available: $${bin}"; \
exit 1; \
fi; \
done; \
\
elif [ "$(FLAVOUR)" = "k8s" ]; then \
for bin in $$( echo $${REQUIRED_BASE} $${REQUIRED_TOOLS} $${REQUIRED_K8S} ); do \
if echo "$${BINS}" | grep -E "^$${bin}" >/dev/null; then \
echo "[OK] required bin available: $${bin}"; \
else \
echo "[FAILED] required bin not available: $${bin}"; \
exit 1; \
fi; \
done; \
\
fi; \
echo "[SUCCESS]"; \
Expand Down
Loading