DevOps | Software Automation | Continuous Integration

Tag: Debian

How To Build & Compile Source Into Debian Package

  • Install dh-make

sudo apt-get install build-essential dh-make

  • Put your source code in tar.gz into a directory. File format is in <filename>-<version>

mkdir mysource

mv mysource-01.tar.gz mysource/

cd mysource

tar -xvzf mysource-01.tar.gz

  • Create the initial Debian package

cd mysource-01

dh_make -f ../mysource-01.tar.gz

  • It will prompt to ask the type of package. Then hit enter to confirm.

Type of package: single binary, indep binary, multiple binary, library, kernel module, kernel patch?
[s/i/m/l/k/n] s

  • A debian folder will be created under mysource-01 with all the necessary debian files

total 108
drwxr-xr-x 3 root root 4096 Dec 6 11:39 .
drwxr-xr-x 3 root root 4096 Dec 6 11:39 ..
-rw-r–r– 1 root root 190 Dec 6 11:39 changelog
-rw-r–r– 1 root root 2 Dec 6 11:39 compat
-rw-r–r– 1 root root 525 Dec 6 11:39 control
-rw-r–r– 1 root root 1679 Dec 6 11:39 copyright
-rw-r–r– 1 root root 0 Dec 6 11:39 docs
-rw-r–r– 1 root root 4596 Dec 6 11:39 init.d.ex
-rw-r–r– 1 root root 1646 Dec 6 11:39 manpage.1.ex
-rw-r–r– 1 root root 4663 Dec 6 11:39 manpage.sgml.ex
-rw-r–r– 1 root root 11018 Dec 6 11:39 manpage.xml.ex
-rw-r–r– 1 root root 129 Dec 6 11:39 menu.ex
-rw-r–r– 1 root root 134 Dec 6 11:39 mysource.cron.d.ex
-rw-r–r– 1 root root 238 Dec 6 11:39 mysource.default.ex
-rw-r–r– 1 root root 526 Dec 6 11:39 mysource.doc-base.EX
-rw-r–r– 1 root root 958 Dec 6 11:39 postinst.ex
-rw-r–r– 1 root root 931 Dec 6 11:39 postrm.ex
-rw-r–r– 1 root root 691 Dec 6 11:39 preinst.ex
-rw-r–r– 1 root root 878 Dec 6 11:39 prerm.ex
-rw-r–r– 1 root root 186 Dec 6 11:39 README.Debian
-rw-r–r– 1 root root 271 Dec 6 11:39 README.source
-rwxr-xr-x 1 root root 114 Dec 6 11:39 rules
drwxr-xr-x 2 root root 4096 Dec 6 11:39 source
-rw-r–r– 1 root root 787 Dec 6 11:39 watch.ex

  • You can then modify the relevant files for eg: control

Docker – How To Run A Debian Package In Docker

Below are the major steps on how to run a Debian package in Docker

Dockerfile
  • Download your Debian file

# Download .deb fileRUN wget $debian_url \
&& sudo dpkg -i appleapi.deb \
&& apt-get install -f

  • Using Ruby Tiller to overwrite environment specific configs (optional)

#Tiller
RUN sudo apt-get update && sudo apt-get -y install ruby
RUN gem install tiller

ADD deploy/tiller/*.yaml /etc/tiller/
ADD deploy/tiller/environments/dev /etc/tiller/environments/
ADD deploy/tiller/templates/* /etc/tiller/templates/

  • Run Tiller and tell it to use development environment configuration

RUN tiller -b /etc/tiller -n -v -e development

  • Expose the port of your app

EXPOSE 9001

  • Start your app via Supervisord (optional as you could just use CMD)

CMD [“/usr/bin/supervisord”]

  • Build the Docker file

docker build  -t appleapi .

  • Run Docker in localhost

docker run -p 9001:9001 appleapi

supervisord.conf

[supervisord]
nodaemon=true

[program:appleapi]
startsecs = 0
autorestart = false
command=/bin/bash -c “appleapi/bin/appleapi”

© 2023 Chuan Chuan Law

Theme by Anders NorenUp ↑