Skip to content

Commit a2eb6d0

Browse files
committed
feat: add nc
1 parent 4d0834f commit a2eb6d0

File tree

4 files changed

+464
-0
lines changed

4 files changed

+464
-0
lines changed

.github/workflows/nc.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: nc
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: "0 5 * * *"
6+
push:
7+
tags:
8+
- 'nc'
9+
jobs:
10+
nc:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: cron-update / get latest version
14+
run: |
15+
LATEST_VERSION=$(curl -sfL https://salsa.debian.org/debian/netcat-openbsd/tags | grep -oE "debian/[0-9]+.[0-9]+" | head -n 1 | sed 's|debian/||')
16+
if [ "${LATEST_VERSION}" != "null" ]; then
17+
if curl -kILs --fail https://hub.docker.com/v2/repositories/11notes/distroless/tags/nc-${LATEST_VERSION}; then
18+
echo "tag ${LATEST_VERSION} exists already!"
19+
else
20+
echo "WORKFLOW_AUTO_UPDATE=true" >> "${GITHUB_ENV}"
21+
echo "LATEST_VERSION=${LATEST_VERSION}" >> "${GITHUB_ENV}"
22+
fi
23+
else
24+
echo "tag ${LATEST_VERSION} is null!"
25+
fi
26+
27+
- name: init / base64 nested json
28+
if: env.WORKFLOW_AUTO_UPDATE == 'true'
29+
uses: actions/github-script@62c3794a3eb6788d9a2a72b219504732c0c9a298
30+
with:
31+
script: |
32+
const { Buffer } = require('node:buffer');
33+
const etc = {
34+
dockerfile:"nc.dockerfile",
35+
tag:"nc",
36+
version:"${{ env.LATEST_VERSION }}",
37+
semver:{disable:{rolling: true}}
38+
};
39+
core.exportVariable('WORKFLOW_BASE64JSON', Buffer.from(JSON.stringify(etc)).toString('base64'));
40+
41+
- name: build docker image
42+
if: env.WORKFLOW_AUTO_UPDATE == 'true'
43+
uses: the-actions-org/workflow-dispatch@3133c5d135c7dbe4be4f9793872b6ef331b53bc7
44+
with:
45+
wait-for-completion: false
46+
workflow: docker.yml
47+
token: "${{ secrets.REPOSITORY_TOKEN }}"
48+
inputs: '{ "release":"false", "readme":"false", "run-name":"nc", "etc":"${{ env.WORKFLOW_BASE64JSON }}" }'

nc.dockerfile

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# ╔═════════════════════════════════════════════════════╗
2+
# ║ SETUP ║
3+
# ╚═════════════════════════════════════════════════════╝
4+
# GLOBAL
5+
ARG APP_UID=1000 \
6+
APP_GID=1000 \
7+
BUILD_SRC=https://salsa.debian.org/debian/netcat-openbsd.git \
8+
BUILD_ROOT=/netcat-openbsd
9+
ARG BUILD_BIN=${BUILD_ROOT}/nc
10+
11+
# :: FOREIGN IMAGES
12+
FROM 11notes/util:bin AS util-bin
13+
14+
15+
# ╔═════════════════════════════════════════════════════╗
16+
# ║ BUILD ║
17+
# ╚═════════════════════════════════════════════════════╝
18+
# :: NC
19+
FROM alpine AS build
20+
COPY --from=util-bin / /
21+
ARG APP_VERSION \
22+
BUILD_SRC \
23+
BUILD_ROOT \
24+
BUILD_BIN
25+
26+
RUN set -ex; \
27+
apk --update --no-cache add \
28+
git \
29+
g++ \
30+
make \
31+
patch \
32+
libbsd-dev \
33+
libbsd-static;
34+
35+
RUN set -ex; \
36+
git clone ${BUILD_SRC} -b debian/${APP_VERSION}-1;
37+
38+
COPY ./src/nc/ /
39+
40+
RUN set -ex; \
41+
cd ${BUILD_ROOT}; \
42+
git apply b64.patch; \
43+
sed -i -e "/SRCS=/s;\(.*\);& base64.c;" Makefile; \
44+
while read -r PATCH; do \
45+
patch -Np1 < debian/patches/${PATCH} || echo "warning"; \
46+
done < debian/patches/series;
47+
48+
RUN set -ex; \
49+
cd ${BUILD_ROOT}; \
50+
make -s -j $(nproc) LDFLAGS="--static" 2>&1 > /dev/null;
51+
52+
RUN set -ex; \
53+
eleven distroless ${BUILD_BIN};
54+
55+
56+
# ╔═════════════════════════════════════════════════════╗
57+
# ║ IMAGE ║
58+
# ╚═════════════════════════════════════════════════════╝
59+
# :: HEADER
60+
FROM scratch
61+
62+
# :: default arguments
63+
ARG TARGETPLATFORM \
64+
TARGETOS \
65+
TARGETARCH \
66+
TARGETVARIANT \
67+
APP_IMAGE \
68+
APP_NAME \
69+
APP_VERSION \
70+
APP_ROOT \
71+
APP_UID \
72+
APP_GID \
73+
APP_NO_CACHE
74+
75+
# :: default environment
76+
ENV APP_IMAGE=${APP_IMAGE} \
77+
APP_NAME=${APP_NAME} \
78+
APP_VERSION=${APP_VERSION} \
79+
APP_ROOT=${APP_ROOT}
80+
81+
# :: multi-stage
82+
COPY --from=build ${APP_ROOT}/ /
83+
84+
# :: EXECUTE
85+
USER ${APP_UID}:${APP_GID}
86+
ENTRYPOINT ["/usr/local/bin/nc"]
87+
CMD ["-version"]

src/nc/netcat-openbsd/b64.patch

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
declare ahead of time so it's not implicit which is invalid in c23
2+
diff --git a/socks.c b/socks.c
3+
index 7c7448c..ce2533d 100644
4+
--- a/socks.c
5+
+++ b/socks.c
6+
@@ -53,6 +54,8 @@
7+
#define SOCKS_DOMAIN 3
8+
#define SOCKS_IPV6 4
9+
10+
+int b64_ntop(const uint8_t *, size_t, char *, size_t);
11+
+
12+
int remote_connect(const char *, const char *, struct addrinfo, char *);
13+
int socks_connect(const char *, const char *, struct addrinfo,
14+
const char *, const char *, struct addrinfo, int,

0 commit comments

Comments
 (0)