Skip to content

Commit

Permalink
Add content
Browse files Browse the repository at this point in the history
  • Loading branch information
1nfiniteloop committed Jul 13, 2021
1 parent 0d10176 commit be477f1
Show file tree
Hide file tree
Showing 74 changed files with 3,003 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See more @ https://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: LLVM
UseTab: Never
IndentWidth: 2
TabWidth: 2
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 0
AccessModifierOffset: -2
PointerAlignment: Left
NamespaceIndentation: None
58 changes: 58 additions & 0 deletions .devcontainer/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
FROM alpine:3.13

RUN sed -i 's|dl-cdn.alpinelinux.org/alpine|ftp.acc.umu.se/mirror/alpinelinux.org|g' /etc/apk/repositories

# base-tools for C and C++
RUN apk update \
&& apk add --no-cache \
autoconf \
automake \
cmake \
g++ \
gcc \
gdb \
libtool \
make \
pkgconf \
&& rm -r /var/cache/apk/*

# Other useful tools for C and C++
RUN apk update \
&& apk add --no-cache \
clang-extra-tools \
valgrind \
&& rm -r /var/cache/apk/*

# Other useful tools.
RUN apk update \
&& apk add --no-cache \
bash \
ca-certificates \
curl \
git \
sudo \
&& rm -r /var/cache/apk/*

# project-specific dependencies
RUN apk update \
&& apk add --no-cache \
openssl-dev \
musl-nscd-dev \
&& rm -r /var/cache/apk/*

RUN adduser \
-s /bin/bash \
-D \
build \
&& addgroup sudo \
&& adduser build sudo \
&& echo -e "\n# Allow sudo without password\n%sudo ALL=(ALL) NOPASSWD:ALL\n" >> /etc/sudoers

# Don't run as root inside container,
# see https://github.com/microsoft/vscode-remote-release/issues/22
ENV HOME /home/build
ENV THIRD_PARTY_ROOT /home/build/third_party
ENV DIST alpine
USER build

CMD ["/bin/bash", "-l"]
17 changes: 17 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Ref: https://code.visualstudio.com/docs/remote/containers#_devcontainerjson-reference
{
"name": "nss-http",
"image": "1nfiniteloop/nss-http-builder",
"extensions": [
"llvm-vs-code-extensions.vscode-clangd",
"ms-vscode.cmake-tools",
"twxs.cmake"
],
"runArgs": [
"--name=nss-http.vscode",
"--volume=vscode.cache:/home/build",
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
]
}
73 changes: 73 additions & 0 deletions .devcontainer/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
FROM ubuntu:focal

ENV DEBIAN_FRONTEND=noninteractive

RUN sed --in-place=~ 's|archive.ubuntu.com|ftp.acc.umu.se|g' /etc/apt/sources.list

# base-tools for C and C++
RUN apt-get update \
&& apt-get install \
--no-install-recommends \
--assume-yes \
--quiet \
autoconf \
automake \
cmake \
g++ \
gcc \
gdb \
libtool \
make \
pkg-config \
&& rm -r /var/lib/apt/lists/*

# Other useful tools for C and C++
RUN apt-get update \
&& apt-get install \
--no-install-recommends \
--assume-yes \
--quiet \
clangd \
valgrind \
&& rm -r /var/lib/apt/lists/*

# Other useful tools.
RUN apt-get update \
&& apt-get install \
--no-install-recommends \
--assume-yes \
--quiet \
ca-certificates \
curl \
git \
less \
nano \
sudo \
xz-utils \
&& rm -r /var/lib/apt/lists/*

# Project-specific dependencies
RUN apt-get update \
&& apt-get install \
--no-install-recommends \
--assume-yes \
--quiet \
libssl-dev \
&& rm -r /var/lib/apt/lists/*

RUN useradd \
--uid 1000 \
--shell /bin/bash \
--create-home \
build \
&& adduser build sudo \
&& echo "\n# Allow sudo without password\n%sudo ALL=(ALL) NOPASSWD:ALL\n" >> /etc/sudoers

# Don't run as root inside container,
# see https://github.com/microsoft/vscode-remote-release/issues/22
ENV HOME /home/build
ENV THIRD_PARTY_ROOT /home/build/third_party
ENV DIST ubuntu
USER build

CMD ["/bin/bash", "-l"]
81 changes: 81 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build app

on:
push:
branches: main
tags:
- 'v*'

jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# ref: https://github.com/docker/build-push-action
- name: Create builder container
uses: docker/build-push-action@v2
with:
context: .
file: .devcontainer/ubuntu/Dockerfile
platforms: linux/amd64
push: true
tags: |
1nfiniteloop/nss-http-builder:latest
1nfiniteloop/nss-http-builder:1.0.0
# ref: https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#-use-an-external-cache-source-for-a-build---cache-from
cache-from: type=registry,ref=1nfiniteloop/nss-http-builder:latest
cache-to: type=inline

# ref: https://github.com/actions/cache
- name: Get cache for third party dependencies
id: cache
uses: actions/cache@v2
with:
path: third_party_root/install
key: third-party-${{ hashFiles('third_party') }}

- name: Build third-party dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
docker run \
--rm \
--user root \
--workdir /home/build \
--env THIRD_PARTY_ROOT=/home/build/nss-http/third_party_root \
--volume $(pwd):/home/build/nss-http \
1nfiniteloop/nss-http-builder /bin/bash -c ' \
mkdir --parents nss-http/third_party_root/source \
&& for dep in nss-http/third_party/{boost,cpr,yaml_cpp}; \
do ${dep} || break; done'
- name: Build nss-http
run: |
docker run \
--rm \
--user root \
--workdir /home/build \
--env THIRD_PARTY_ROOT=/home/build/nss-http/third_party_root \
--volume $(pwd):/home/build/nss-http \
1nfiniteloop/nss-http-builder /bin/bash -c ' \
mkdir --parents nss-http/build/Release
cmake \
-D VERSION=1.0.0 \
-D BUILD=Release \
-D UNITTEST=OFF \
-S nss-http \
-B nss-http/build/Release \
&& make --directory=nss-http/build/Release package'
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# Project
build/
.vscode/
.clangd/
compile_commands.json
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.5)
project(nss-http
VERSION ${VERSION}
DESCRIPTION "Name service switch implementation for query unix accounts over http"
HOMEPAGE_URL "https://github.com/1nfiniteloop/nss-http"
)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake-module)
set(CMAKE_BUILD_TYPE ${BUILD})
option(UNITTEST "Build unit tests and its dependencies" ON)

# Language-specific settings
add_compile_options(-Wall -Wextra -pedantic -Werror)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb3")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

# THIRD_PARTY_ROOT and DIST provided from Dockerfile
set(CMAKE_PREFIX_PATH
$ENV{THIRD_PARTY_ROOT}/install/$ENV{DIST}/boost_1_75_0
$ENV{THIRD_PARTY_ROOT}/install/$ENV{DIST}/cpr-1.6.2
$ENV{THIRD_PARTY_ROOT}/install/$ENV{DIST}/yaml-cpp-0.6.3
$ENV{THIRD_PARTY_ROOT}/install/$ENV{DIST}/googletest-release-1.10.0
)

if (UNITTEST)
include(ImportGTest)
enable_testing()
add_custom_target(test_all COMMAND ${CMAKE_CTEST_COMMAND})
endif()

# Third party dependencies:
include(ImportBoost)
include(ImportCpr)
include(ImportYamlCpp)

# Project components
add_subdirectory(debian)
add_subdirectory(source)

# Package
include(PackageDebian)
Loading

0 comments on commit be477f1

Please sign in to comment.