1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Dockerでdebファイルのビルドをする

Last updated at Posted at 2020-04-11

3つのファイルを使います

build.sh
#!/bin/bash
set -e
if [[ $UID == 0 ]]; then
    echo "You must not run this as root." 1>&2
    exit 1
fi

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

# dockerコンテナビルド前に行う処理はここから
WORKDIR=$(cd $(dirname $0); pwd)
NAME=base-files-11ubuntu4
#ここまでの間に記述する

# イメージ名build_debはビルドするdebファイルによって書き換える
# 例: 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

Dockerfile

FROM ubuntu:20.04
ARG NAME="base-files-11ubuntu4"
#ビルド対象のディレクトリ名を記述
ARG UID=65587
#コンフリクトしないように大きい値で
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
# 依存関係をインストールする

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
#sudoがパスワード入力無しで使えるユーザの作成

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
USER ${UID}
WORKDIR /debuild
CMD ["./debuild.sh"]
debuild.sh
#!/bin/bash -e
if [ $UID != 65587 ]; then
    echo "You have to run this on Docker" 1>&2
    exit 1
fi
#Dockerコンテナ以外で実行されることを抑制

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

#ビルド前の処理を記述

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 \
lsb-release-udeb_${BASE_FILES:11}serene${VERSION:5}_all.udeb
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.zstに圧縮、ソースパッケージと共にホストとの共有ディレクトリへ
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?