diff --git a/.github/workflows/deploy_images.yaml b/.github/workflows/deploy_images.yaml new file mode 100644 index 0000000..bf1ff00 --- /dev/null +++ b/.github/workflows/deploy_images.yaml @@ -0,0 +1,24 @@ +name: deploy_images +on: + release: + types: [published] + +jobs: + publish-docker-images: + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ secrets.GITHUB_USERNAME }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push python base + run: | + docker build ./Docker/python.dockerfile --tag ghcr.io/PythonBiellaGroup/python-base:latest + docker run ghcr.io/PythonBiellaGroup/python-base:latest + docker push ghcr.io/PythonBiellaGroup/python-base:latest \ No newline at end of file diff --git a/Docker/helm.dockerfile b/Docker/helm.dockerfile new file mode 100644 index 0000000..41f84eb --- /dev/null +++ b/Docker/helm.dockerfile @@ -0,0 +1,17 @@ +FROM ubuntu:20.04 AS builder + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends curl ca-certificates + +WORKDIR /tmp +RUN curl -LO "https://dl.k8s.io/release/v1.27.3/bin/linux/amd64/kubectl" +RUN curl -Lo helm.tar.gz "https://get.helm.sh/helm-v3.12.1-linux-amd64.tar.gz" && tar -xf helm.tar.gz && cp linux-amd64/helm /usr/local/bin/helm +RUN chmod +x /tmp/kubectl /tmp/linux-amd64/helm + +FROM ubuntu:20.04 +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends curl ca-certificates gettext-base \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /tmp/kubectl /usr/local/bin/kubectl +COPY --from=builder /tmp/linux-amd64/helm /usr/local/bin/helm diff --git a/Docker/node.dockerfile b/Docker/node.dockerfile new file mode 100644 index 0000000..b206d66 --- /dev/null +++ b/Docker/node.dockerfile @@ -0,0 +1,31 @@ +FROM node:lts + +RUN DEBIAN_FRONTEND=noninteractive apt update && apt install -y \ + libpq-dev gcc wget curl gnupg2 openssh-client make build-essential git \ + && mkdir -p ~/.ssh + +# COPY bin/ssh-config.sh /usr/bin/ssh-config.sh +# COPY ./config /root/.ssh/config +# RUN chmod 400 /root/.ssh/config +# RUN chmod +x /usr/bin/ssh-config.sh + +# add custom host file +# COPY hosts tmp/ +# ADD hosts /tmp/hosts +# Warning: if you test on M1 and arch64 architecture you could have an issue with this line +# If you are using mac or arch64 change x86_64-linux-gnu with aarch64-linux-gnu +# RUN mkdir -p -- /lib-override && cp /lib/x86_64-linux-gnu/libnss_files.so.2 /lib-override +# RUN perl -pi -e 's:/etc/hosts:/tmp/hosts:g' /lib-override/libnss_files.so.2 +# ENV LD_LIBRARY_PATH /lib-override + + +# add custom config file +# COPY config tmp/ +# ADD config temp/config +# ADD config /root/.ssh/config +# Warning: if you test on M1 and arch64 architecture you could have an issue with this line +# If you are using mac or arch64 change x86_64-linux-gnu with aarch64-linux-gnu +# RUN mkdir -p -- /lib-override && cp /lib/x86_64-linux-gnu/libnss_files.so.2 /lib-override +# RUN perl -pi -e 's:/root/.ssh/config:/tmp/config:g' /lib-override/libnss_files.so.2 +# ENV LD_LIBRARY_PATH /lib-override +# RUN chmod 400 /root/.ssh/config diff --git a/Docker/pdm.dockerfile b/Docker/pdm.dockerfile new file mode 100644 index 0000000..4b7cc30 --- /dev/null +++ b/Docker/pdm.dockerfile @@ -0,0 +1,32 @@ +# Python PDM Base dockerfile image +FROM python:3.9.16-slim-buster as python + +# Metadata +LABEL name="Python3.9 PDM" +LABEL maintainer="PythonBiellaGroup" +LABEL version="0.1" + +ARG PDM_VERSION="2.7.0" + +# Install libraries +RUN DEBIAN_FRONTEND=noninteractive apt update && DEBIAN_FRONTEND=noninteractive apt install -y \ + libpq-dev gcc wget gnupg2 curl openssh-client git make build-essential \ + make build-essential libssl-dev zlib1g-dev \ + libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \ + libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev + +# add custom host file +# COPY hosts tmp/ +# ADD hosts /tmp/hosts +# Warning: if you test on M1 and arch64 architecture you could have an issue with this line +# If you are using mac or arch64 change x86_64-linux-gnu with aarch64-linux-gnu +# RUN mkdir -p -- /lib-override && cp /lib/x86_64-linux-gnu/libnss_files.so.2 /lib-override +# RUN perl -pi -e 's:/etc/hosts:/tmp/hosts:g' /lib-override/libnss_files.so.2 +# ENV LD_LIBRARY_PATH /lib-override + +# install PDM +RUN pip install -U pip setuptools wheel +RUN pip install pdm==${PDM_VERSION} + +#if you want to test the image +# CMD ["tail", "-f", "/dev/null"] diff --git a/Docker/python.dockerfile b/Docker/python.dockerfile new file mode 100644 index 0000000..398f5e5 --- /dev/null +++ b/Docker/python.dockerfile @@ -0,0 +1,57 @@ +FROM python:3.9.16-slim-buster as python + +# Metadata +LABEL name="Python3.9 Poetry" +LABEL maintainer="PythonBiellaGroup" +LABEL version="0.1" + +ARG YOUR_ENV="virtualenv" +ARG POETRY_VERSION="1.5.1" + +ENV YOUR_ENV=${YOUR_ENV} \ + PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PYTHONFAULTHANDLER=1 \ + PYTHONHASHSEED=random \ + PIP_NO_CACHE_DIR=off \ + PIP_DISABLE_PIP_VERSION_CHECK=on \ + PIP_DEFAULT_TIMEOUT=100 \ + POETRY_HOME=/opt/poetry \ + POETRY_VIRTUALENVS_CREATE=false \ + POETRY_VIRTUALENVS_IN_PROJECT=false \ + POETRY_NO_INTERACTION=1 \ + POETRY_VERSION=${POETRY_VERSION} \ + LC_ALL=C.UTF-8 \ + LANG=C.UTF-8 + +ENV PATH="$POETRY_HOME/bin:$PATH" + +# add ssh config capabilities +# RUN mkdir -p ~/.ssh +# COPY bin/ssh-config.sh /usr/bin +# RUN chmod +x /usr/bin/ssh-config.sh + +# Install libraries +RUN DEBIAN_FRONTEND=noninteractive apt update && apt install -y \ + libpq-dev gcc wget gnupg2 curl openssh-client git make build-essential \ + make build-essential libssl-dev zlib1g-dev \ + libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \ + libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev + +# add custom host file +# COPY hosts tmp/ +# ADD hosts /tmp/hosts +# Warning: if you test on M1 and arch64 architecture you could have an issue with this line +# If you are using mac or arch64 change x86_64-linux-gnu with aarch64-linux-gnu +# RUN mkdir -p -- /lib-override && cp /lib/x86_64-linux-gnu/libnss_files.so.2 /lib-override +# RUN perl -pi -e 's:/etc/hosts:/tmp/hosts:g' /lib-override/libnss_files.so.2 +# ENV LD_LIBRARY_PATH /lib-override + +RUN wget -O install-poetry.py https://install.python-poetry.org/ \ + && python install-poetry.py --version ${POETRY_VERSION} + +# COPY pyproject.toml . +# RUN poetry install + +#if you want to test the image +# CMD ["tail", "-f", "/dev/null"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b097158 --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +.PHONY: docker +docker_build: + docker-compose -p test build + +docker_python: + docker-compose -p test up --build -d ai-python-base + +docker_pdm: + docker-compose -p test up --build -d ai-pdm-python-base + +docker_check: + docker ps -a | grep "test" + +docker_stop: + docker-compose -p test down + +docker_stop_volume: + docker-compose -p test down -v + +docker_volume_prune: + docker volume prune + +docker_volume_list: + docker volume list diff --git a/README.md b/README.md index 674435f..50ce6a0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,82 @@ -# Dockbase -Base docker images for PythonBiellaGroup +# Docker Images + +Base PythonBiellaGroup docker images + +The aim of this project is to create default Docker image that everyone can use for building applications + +## Images available: + +- Python base image: this image it's used to build python with poetry +- PDM: Python base image with PDM support +- Node: base nodejs image +- Ubuntu CI Image: this image it's used by the infrastructure projects to build, push and launch code inside a deployment production server by ci/cd. + +## Deploy a new image + +If you want to create new images and launch the CI/CD pipeline you have to define a new tag. + +```bash +# visualize the list of tags +git tag -l + +# create a new tag +git tag 0.0.x + +# push the tag and launch the pipeline +git push --tag +``` + +The tags are defined by the following structure: `major.minor.patch` + +## Debug and test an image + +You can use the `makefile` inside this project to launch and debug the images with your local machine. + +There is also a `pyproject.toml` that contains all our libraries that we are using in the projects so you can test also the python installation of the libraries. + +```bash +# build the images +make docker_build + +# visualize images builded +docker image ls + +# startup container from image +docker run --entrypoint "/bin/bash" --rm image:latest -c "sleep 24h" + +# container hash id +docker ps + +# log into the running container +docker exec -ti containerid bash + +# output logs of the container +docker logs -f containerid +``` + +## Pull and use an image + +If you want to pull and use an image inside the registry you can do: +```bash +# docker login +docker login gitlab.com -u $TOKEN_NAME -p $TOKEN_PASSWORD + +# build a specific image (with a version) +docker build -t gitlab.com . + +``` + +The variables: `TOKEN_NAME` and `TOKEN_PASSWORD` are defined inside gitlab. + +## Push manually an image to the registry + +This is something you don't have to do, because this process it's done automatically by the CI/CD pipeline. +```bash +docker login gitlab.com -u $TOKEN_NAME -p $TOKEN_PASSWORD + +docker push gitlab.com +``` + +## Other informations + +Informations regarding pipeline in Github and how to publish the docker, please check the [official github documentation](https://docs.github.com/en/actions/publishing-packages/publishing-docker-images) \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..1674a57 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,21 @@ +version: "3.8" +services: + #Default standard ai python base image + ai-python-base: + build: + dockerfile: ./Docker/python.dockerfile + context: . + container_name: ai-python-base + command: "tail -f /dev/null" + restart: always + environment: + TEST: ${TEST:-"docker-compose dev"} + ai-pdm-python-base: + build: + dockerfile: ./Docker/pdm.dockerfile + context: . + container_name: ai-pdm-base + command: "tail -f /dev/null" + restart: always + environment: + TEST: ${TEST:-"docker-compose dev"} \ No newline at end of file