[LINUX] Build a deb file with Docker

Use 3 files


set -e
if [[ $UID == 0 ]]; then
    echo "You must not run this as root." 1>&2
    exit 1

if !(type docker >/dev/null); then
    echo "Docker is not installing on this machine." 1>&2
    exit 1

#Click here for the processing to be performed before building the docker container
WORKDIR=$(cd $(dirname $0); pwd)
#Described so far

#Image name build_deb is rewritten by the deb file to build
#Example: build_base-files
sudo docker build -t build_deb ${WORKDIR}
sudo docker run -e NAME=${NAME} -e UGID="${UID}:$(id -u)" -v ${WORKDIR}/out:/deb -it build_deb


FROM ubuntu:20.04
ARG NAME="base-files-11ubuntu4"
#Describe the directory name to be built
ARG UID=65587
#With a large value so as not to conflict
RUN sed -i"" -e 's%http://[^ ]\+%mirror://mirrors.ubuntu.com/mirrors.txt%g' /etc/apt/sources.list \
&& apt-get update \
&& apt-get -y upgrade \
&& apt-get install -y --no-install-recommends build-essential devscripts zstd gawk libc6 libcrypt1 debhelper dh-systemd apt-utils sudo \
&& rm -rf /tmp/* /var/tmp/* \
&& apt-get clean
#Install dependencies

RUN echo "root:root" | chpasswd && \
    adduser --disabled-password --uid ${UID} --gecos "" docker && \
    echo "docker:docker" | chpasswd && \
    echo "%docker    ALL=(ALL)   NOPASSWD:    ALL" >> /etc/sudoers.d/docker && \
    chmod 0440 /etc/sudoers.d/docker
#Creating a user that sudo can use without entering a password

RUN mkdir -p /debuild/build /deb 
ADD ./${NAME} /debuild/build/${NAME}
ADD ./debuild.sh /debuild/debuild.sh
RUN chmod +x /debuild/debuild.sh \
&& chown -R docker:docker /debuild
WORKDIR /debuild
CMD ["./debuild.sh"]


#!/bin/bash -e
if [ $UID != 65587 ]; then
    echo "You have to run this on Docker" 1>&2
    exit 1
#Suppress running outside of Docker container

export EDITOR=vim
cd /debuild/build/$NAME

#Describe the process before build

debuild -us -uc

cd ..
tar cf ${BASE_FILES}serene${VERSION:5}.tar \
base-files-dbgsym_${BASE_FILES:11}serene${VERSION:5}_amd64.ddeb \
base-files_${BASE_FILES:11}serene${VERSION:5}.dsc \
base-files_${BASE_FILES:11}serene${VERSION:5}_amd64.build \
base-files_${BASE_FILES:11}serene${VERSION:5}_amd64.buildinfo \
base-files_${BASE_FILES:11}serene${VERSION:5}_amd64.changes \
base-files_${BASE_FILES:11}serene${VERSION:5}_amd64.deb \
zstd ${BASE_FILES}serene${VERSION:5}.tar
sudo mv -f *.xz /deb 2>/dev/null
sudo mv -f *.zst /deb 2>/dev/null
sudo chown -R ${H_UGID} /deb 2>/dev/null
#Tar the build.Compress to zst, to shared directory with host with source package

Recommended Posts

Build a deb file with Docker
[Linux] Build a jenkins environment with Docker
[Linux] Build a Docker environment with Amazon Linux 2
[Python] Build a Django development environment with Docker
Build a development environment with Poetry Django Docker Pycharm
Build a Django development environment with Docker! (Docker-compose / Django / postgreSQL / nginx)
[Memo] Build a development environment for Django + Nuxt.js with Docker
Build a go environment using Docker
Build Mysql + Python environment with docker
Deploy a Django application with Docker
[Django] Build a Django container (Docker) development environment quickly with PyCharm
Build PyPy execution environment with Docker
Build a web application with Django
Create a Todo app with Django ① Build an environment with Docker
Create a file uploader with Django
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
Easily build a development environment with Laragon
Build Jupyter Lab (Python) environment with Docker
Build a blockchain with Python ① Create a class
Set up a Samba server with Docker
Build a Tensorflow environment with Raspberry Pi [2020]
Build a Fast API environment with docker-compose
Get a local DynamoDB environment with Docker
Let's scrape a dynamic site with Docker
Create a large text file with shellscript
Create a VM with a YAML file (KVM)
Create a deb file from a python package
Run a Python web application with Docker
Build a python virtual environment with pyenv
Create a web service with Docker + Flask
Read a character data file with numpy
Build a capture acquisition machine with Selenium
Build a modern Python environment with Neovim
Build static library (.a) together with waf
Build NGINX + NGINX Unit + MySQL environment with Docker
I made a configuration file with Python
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Easy construction]
Build a CentOS Linux 8 environment with Docker and start Apache HTTP Server
Build a local server with a single command [Mac]
Build a LAMP environment on your local Docker
How to read a CSV file with Python 2/3
Build a C language development environment with a container
Build a WardPress environment on AWS with pulumi
Speaking Japanese with gTTS (reading a text file)
Go (Echo) Go Modules × Build development environment with Docker
Build a python environment with ansible on centos6
Create a PDF file with a random page size
Start a simple Python web server with Docker
Create a python3 build environment with Sublime Text3
Build a cheap summarization system with AWS components
Build a Django environment with Vagrant in 5 minutes
[Memo] Build a virtual environment with Pyenv + anaconda
Build a virtual environment with pyenv and venv
Build a Django development environment with Doker Toolbox
Save the object to a file with pickle
Draw a graph with matplotlib from a csv file
Create a Photoshop format file (.psd) with python
Build a Python environment with OSX El capitan
Quickly build a Python Django environment with IntelliJ
Read line by line from a file with Python
I want to write to a file with Python