Skip to content

Commit

Permalink
S7IPA-169 Add docker-based ubuntu packaging for libpostal (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmorano committed Jul 3, 2020
1 parent 790e24b commit 99c6f48
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/docker-builds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: docker builds
on: [push, pull_request]

jobs:
build:
name: Build OS packages inside a docker container and create release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Make git short-commit available for the different steps
id: metadata
env:
UBUNTU_VERSIONS: 16.04 18.04
run: |
echo "::set-output name=commit::$(echo ${GITHUB_SHA} | head -c7)"
echo "::set-output name=version::$(sed 's|^v||' versions/parser)"
- name: Build
env:
DOCKER_IMAGE_NAME: stuart/libpostal
UBUNTU_VERSIONS: "16.04 18.04"
run: |
pwd
ls -hal
git status -sb
for ubuver in ${UBUNTU_VERSIONS}
do
docker build \
--build-arg UBUNTU_VERSION=${ubuver} \
-t ${DOCKER_IMAGE_NAME}:${ubuver} .
CID=$(docker create ${DOCKER_IMAGE_NAME}:${ubuver})
docker cp ${CID}:/output ./output-ubuntu-${ubuver}
done
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ steps.metadata.outputs.version }}-${{ steps.metadata.outputs.commit }}
release_name: Release ${{ steps.metadata.outputs.version }}-${{ steps.metadata.outputs.commit }}
body: |
Automatically generated by GH action on this project
draft: false
prerelease: false
- name: Upload .deb package release asset (ubuntu-16.04)
id: upload-deb-release-asset-ubuntu-16-04
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./output-ubuntu-16.04/libpostal_${{ steps.metadata.outputs.version }}+git${{ steps.metadata.outputs.commit }}_amd64.deb
asset_name: ubuntu-16.04-libpostal_${{ steps.metadata.outputs.version }}+git${{ steps.metadata.outputs.commit }}_amd64.deb #FIXME: find a way to dynamically set upstream version
asset_content_type: application/vnd.debian.binary-package
- name: Upload data release asset (ubuntu-16.04)
id: upload-data-release-asset-ubuntu-16-04
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./output-ubuntu-16.04/data.tgz
asset_name: ubuntu-16.04-data-${{ steps.metadata.outputs.version }}-${{ steps.metadata.outputs.commit }}.tar.gz #FIXME: find a way to dynamically set upstream version
asset_content_type: application/tar+gzip
- name: Upload .deb package release asset (ubuntu-18.04)
id: upload-deb-release-asset-ubuntu-18-04
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./output-ubuntu-18.04/libpostal_${{ steps.metadata.outputs.version }}+git${{ steps.metadata.outputs.commit }}_amd64.deb
asset_name: ubuntu-18.04-libpostal_${{ steps.metadata.outputs.version }}+git${{ steps.metadata.outputs.commit }}_amd64.deb #FIXME: find a way to dynamically set upstream version
asset_content_type: application/vnd.debian.binary-package
- name: Upload data release asset (ubuntu-18.04)
id: upload-data-release-asset-ubuntu-18-04
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./output-ubuntu-18.04/data.tgz
asset_name: ubuntu-18.04-data-${{ steps.metadata.outputs.version }}-${{ steps.metadata.outputs.commit }}.tar.gz #FIXME: find a way to dynamically set upstream version
asset_content_type: application/tar+gzip
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG UBUNTU_VERSION="18.04"
FROM ubuntu:${UBUNTU_VERSION}
ARG DEB_PACKAGE_NAME="libpostal"
ARG DEB_PACKAGE_DESC="Debian wrapping for https://github.com/openvenues/libpostal"
ARG DEB_PACKAGE_VERSION="0.0.1"
ARG BASE_PACKAGES="ruby ruby-dev rubygems build-essential curl autoconf automake libtool pkg-config git gettext"
ENV APT_ARGS="-y -o APT::Install-Suggests=false -o APT::Install-Recommends=false"

RUN apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install ${APT_ARGS} ${BASE_PACKAGES} && \
gem install --no-document fpm
COPY ./ /src
WORKDIR /src
RUN bash bootstrap.sh && \
mkdir -p /output/usr && \
./configure --prefix=/output/usr && \
make -j && \
make install
# move out big files from the package
WORKDIR /output
RUN tar -zcf data.tgz usr/share/libpostal && \
rm -rf /output/usr/share/libpostal/*
# build deb package
RUN export DEB_PACKAGE_VERSION=$(sed 's|^v||' /src/versions/parser)+git$(bash -c 'cd /src; git rev-parse HEAD | head -c7') && \
envsubst '${DEB_PACKAGE_VERSION}' < /src/assets/fpm-deb-scripts/postinst.sh.tpl > /src/assets/fpm-deb-scripts/postinst.sh && \
fpm -n ${DEB_PACKAGE_NAME} \
-v ${DEB_PACKAGE_VERSION} \
--description "${DEB_PACKAGE_DESC}" \
-s dir \
-t deb \
--after-install /src/assets/fpm-deb-scripts/postinst.sh \
/output/usr=/
46 changes: 46 additions & 0 deletions assets/fpm-deb-scripts/postinst.sh.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

download_data() {
. /etc/lsb-release
if [ "${DISTRIB_ID}" = "Ubuntu" ]
then
curl -sL https://github.com/StuartApp/libpostal/releases/download/${GH_RELEASE}/ubuntu-${DISTRIB_RELEASE}-data-${GH_RELEASE}.tar.gz | tar -C / -zxf -
fi
}

after_upgrade() {
echo "Upgrading data package '${GH_RELEASE}' from GH releases..."
download_data
}

after_install() {
echo "Installing data package '${GH_RELEASE}' from GH releases..."
download_data
}

export PACKAGE_VERSION=${DEB_PACKAGE_VERSION}
export GH_RELEASE=$(echo ${PACKAGE_VERSION} | sed 's|+git|-|')

if [ "${1}" = "configure" -a -z "${2}" ] || \
[ "${1}" = "abort-remove" ]
then
# "after install" here
# "abort-remove" happens when the pre-removal script failed.
# In that case, this script, which should be idemptoent, is run
# to ensure a clean roll-back of the removal.
installingVersion="${2}"
after_install
elif [ "${1}" = "configure" -a -n "${2}" ]
then
upgradeFromVersion="${2}"
# "after upgrade" here
# NOTE: This slot is also used when deb packages are removed,
# but their config files aren't, but a newer version of the
# package is installed later, called "Config-Files" state.
# basically, that still looks a _lot_ like an upgrade to me.
after_upgrade "${2}"
elif echo "${1}" | grep -E -q "(abort|fail)"
then
echo "Failed to install before the post-installation script was run." >&2
exit 1
fi

0 comments on commit 99c6f48

Please sign in to comment.