Skip to content

Commit

Permalink
migrate to golang
Browse files Browse the repository at this point in the history
  • Loading branch information
zeriyoshi committed Jul 24, 2024
1 parent c7a033f commit e945f66
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Container CI

on:
workflow_dispatch:
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/go_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Golang CI

on:
workflow_dispatch:
pull_request_target:
push:
branches:
- main

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
- name: Install dependencies
run: go mod download
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
- name: Check formatting
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
echo "The following files are not formatted correctly:"
gofmt -s -l .
exit 1
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.DS_Store
dependency_resolve
22 changes: 16 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
ARG _DEB_VERSION="12"

ARG ARCH="arm64/v8"
ARG PLATFORM="linux/arm64/v8"

ARG BASE="debian:${_DEB_VERSION}"
ARG BASE_PKGS="php"
ARG BASE_BINS="php"
ARG BASE_PKG_INSTALL_CMD="apt-get update && apt-get install -y"

ARG GOLANG="golang:latest"

ARG BUSYBOX="busybox:latest"

ARG TARGET="gcr.io/distroless/base-nossl-debian${_DEB_VERSION}:latest"

FROM --platform="linux/${ARCH}" ${BUSYBOX} AS busybox
FROM --platform="${PLATFORM}" ${GOLANG} AS golang

COPY "./" "/build"

RUN cd "/build" \
&& go get \
&& go build -o "/usr/local/bin/dependency_resolve" . \
&& cd -

FROM --platform="${PLATFORM}" ${BUSYBOX} AS busybox

FROM --platform="linux/${ARCH}" ${BASE} AS base
FROM --platform="${PLATFORM}" ${BASE} AS base

ARG BASE_PKGS
ARG BASE_BINS
ARG BASE_PKG_INSTALL_CMD

COPY --chmod=755 "dependency_resolve" "/usr/local/bin/dependency_resolve"
COPY --from=golang "/usr/local/bin/dependency_resolve" "/usr/local/bin/dependency_resolve"

RUN /bin/sh -c "${BASE_PKG_INSTALL_CMD} ${BASE_PKGS}" \
&& /usr/local/bin/dependency_resolve \
"$(which "ldd")" \
$(echo "${BASE_BINS}" | xargs which) \
| xargs -I {} sh -c 'mkdir -p /root/rootfs/$(dirname "{}") && cp -apP "{}" "/root/rootfs/{}"'

FROM --platform="linux/${ARCH}" ${TARGET} AS target
FROM --platform="${PLATFORM}" ${TARGET} AS target

ARG BASE_BINS

Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ Binary packaging support tool for distroless / alpine.

```Dockerfile
FROM debian:12 AS builder
COPY --chmod=755 "dependency_resolve" "/usr/local/bin/dependency_resolve"
FROM --platform="${PLATFORM}" ${GOLANG} AS golang
COPY "./" "/build"
RUN cd "/build" \
&& go get \
&& go build -o "/usr/local/bin/dependency_resolve" . \
&& cd -
COPY --from=golang "/usr/local/bin/dependency_resolve" "/usr/local/bin/dependency_resolve"
RUN apt-get update && apt-get install -y "php"
RUN dependency_resolve "$(which "ldd")" "$(which "php")" | xargs -I {} sh -c 'mkdir -p /root/rootfs/$(dirname "{}") && cp -apP "{}" "/root/rootfs/{}"'
RUN /usr/local/bin/dependency_resolve "$(which "php")" | xargs -I {} sh -c 'mkdir -p /rootfs/$(dirname "{}") && cp -apP "{}" "/rootfs/{}"'

FROM gcr.io/distroless/base-nossl-debian12:latest
COPY --from=builder "/root/rootfs" "/"
COPY --from=builder "/rootfs" "/"

ENTRYPOINT ["/usr/bin/php"]
```
Expand Down
115 changes: 0 additions & 115 deletions dependency_resolve

This file was deleted.

Loading

0 comments on commit e945f66

Please sign in to comment.