building .deb packages #13

Merged
ben merged 3 commits from deb into main 2022-11-09 15:46:15 +00:00
6 changed files with 69 additions and 2 deletions

View File

@ -18,11 +18,16 @@ RUN apt-get update && \
mkdir -p /opt/${REPO_NAME} && \
chown -R -v ${USER_NAME}. /opt/${REPO_NAME}
USER ${USER_NAME}
WORKDIR /home/${USER_NAME}
ENV PATH="/home/${USER_NAME}/.local/bin:${PATH}"
FROM base as builder
RUN apt-get update && \
apt-get install -y ruby ruby-dev rubygems && \
apt-get autoremove && \
apt-get autoclean && \
gem install --no-document fpm
USER ${USER_NAME}
ARG PIP_REPO_URL="https://git.sudo.is/api/packages/ben/pypi"
ARG PIP_REPO_NAME="gitea"
WORKDIR /opt/${REPO_NAME}
@ -34,6 +39,9 @@ RUN python3 -m pip install poetry --pre && \
echo "repositories configured for poetry:" && \
python3 -m poetry config repositories && \
poetry self -V
# python3 -m poetry config cache-dir "/usr/local/virtualenvs" && \
COPY --chown=${USER_NAME} .flake8 poetry.lock pyproject.toml /opt/${REPO_NAME}/
# install dependencies with poetry and then freeze them in a file, so
@ -56,10 +64,17 @@ RUN poetry run pytest && \
# because this way we dont need to deal with permissions
RUN poetry build --no-interaction
COPY --chown=${USERNAME} deb /opt/${REPO_NAME}/deb/
COPY --chown=${USERNAME} scripts/build/build-deb.sh /usr/local/bin/build-deb.sh
RUN /usr/local/bin/build-deb.sh
RUN dpkg -I dist/sudoisbot_*.deb && dpkg -c dist/sudoisbot_*.deb
ENTRYPOINT ["poetry"]
CMD ["build"]
FROM base as final
USER ${USER_NAME}
COPY --chown=${USER_NAME} --from=builder /opt/${REPO_NAME}/requirements.txt /opt/${REPO_NAME}/
RUN python3 -m pip install -r /opt/${REPO_NAME}/requirements.txt && \
python3 -m pip cache purge && \

2
Jenkinsfile vendored
View File

@ -1,7 +1,7 @@
@Library('shared-jenkins-pipelines') _
// source:
// https://git.sudo.is/ben/shared-jenkins-pipelines/src/branch/main/vars/pythondocker.groovy
// https://git.sudo.is/ben/shared-jenkins-pipelines/src/branch/main/vars/poetry.groovy
poetry(
docker: true,

9
deb/after-install.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
systemctl daemon-reload
if `systemctl is-active --quiet sudoisbot@temp_pub`; then
echo -n "restarting temp_pub..."
service sudoisbot@temp_pub restart
echo "ok"
fi

View File

@ -0,0 +1,14 @@
[Unit]
Description=sudoisbot
After=syslog.target
[Service]
User=sudoisbot
Group=sudoisbot
WorkingDirectory=/var/lib/sudoisbot
ExecStart=/usr/local/bin/sudoisbot %I
Restart=on-failure
RestartSec=6
[Install]
WantedBy=multi-user.target

29
scripts/build/build-deb.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
set -e
DEPS="-d python3.10"
pypoetry_venv_path=$(poetry env info -p)
version=$(poetry version -s)
pwd=$(pwd)
echo "pypoetry_venv_path: $pypoetry_venv_path"
echo "version: $version"
fpm \
-a all \
-t deb \
$DEPS \
-n ${REPO_NAME} \
-v ${version} \
--config-files /etc/systemd/system/sudoisbot@.service \
--after-install deb/after-install.sh \
-s dir \
$pypoetry_venv_path \
$pypoetry_venv_path=/usr/local/virtualenvs/${REPO_NAME} \
$(pwd)/deb/etc/systemd/system/=/etc/systemd/system/
mv -v ${REPO_NAME}_*.deb dist/