« /home/rc

Incapache Is Not Comparable to Apache

05/02/2021

Incapache is an assignment from my OS&Networks course I submitted with two friends. Here you can find the repository with source code, check out README.md (ITA)

Please do not copy, you are hurting yourself :)

Stuff I added/modified:

Here is the Dockerfile I used to deploy and test:

FROM ubuntu:latest AS builder

ADD *.c *.h /incapache/
WORKDIR /incapache
RUN apt update && apt install -y build-essential
RUN gcc -DLOG_USE_COLOR -DDEBUG *.c -o incapache -lpthread

FROM ubuntu:latest

RUN apt update && apt install -y file curl python3 python3-pip
RUN  useradd -ms /bin/bash web
WORKDIR /home/web/incapache
ADD test.py requirements.txt ./
ADD www www
COPY --from=builder incapache .
RUN chown root incapache && chmod u+s incapache
USER web
CMD [ "./incapache", "www","8000" ]

This is the config file used to build and deploy using GitLab CI/CD in a pretty trivial way:

stages:
  - build
  - test
  - deploy

build:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - mkdir -p /kaniko/.docker
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:latest

test:
  stage: test
  image: docker:latest
  services:
    - docker:dind
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker run --name incapache -d -p 8000:8000 $CI_REGISTRY_IMAGE
    - docker exec incapache pip3 install -r requirements.txt
    - docker exec incapache python3 test.py 8000
    -
deploy:
  stage: deploy
  image: alpine:latest
  script:
    - apk add openssh
    - eval $(ssh-agent -s)
    - echo "$SSH_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - ssh -o StrictHostKeyChecking=no rc@s.rcastellotti.dev "docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY"
    - ssh -o StrictHostKeyChecking=no rc@s.rcastellotti.dev "docker container rm -f incapache"
    - ssh -o StrictHostKeyChecking=no rc@s.rcastellotti.dev "docker pull $CI_REGISTRY_IMAGE:latest"
    - ssh -o StrictHostKeyChecking=no rc@s.rcastellotti.dev "docker run --name incapache -d -p 8000:8000 $CI_REGISTRY_IMAGE:latest"