Skip to content

Commit

Permalink
Builds musl version fully static
Browse files Browse the repository at this point in the history
  • Loading branch information
ogarcia committed Jan 18, 2025
1 parent 300e246 commit 60d9a78
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 41 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.78.0
- name: Build
run: cargo build --release --locked
run: |
docker run --rm -v $(pwd):/app -w /app rust:alpine sh -c "
apk -U --no-progress add musl-dev sqlite-dev sqlite-static
cargo build --release --locked
"
- name: Package current compilation
id: package-current
run: |
Expand Down
62 changes: 30 additions & 32 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ variables:
QUAY_REGISTRY_URL: "quay.io"
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/rockpass/${CI_COMMIT_TAG}"
ARTIFACTS_AMD64_GLIBC: rockpass-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}-linux-amd64-glibc
ARTIFACTS_AMD64_MUSL: rockpass-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}-linux-amd64-musl
ARTIFACTS_AMD64_STATIC: rockpass-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}-linux-amd64-static
ARTIFACTS_ARM64: rockpass-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}-linux-arm64
PACKAGE_NAME_AMD64_GLIBC: rockpass-${CI_COMMIT_TAG}-linux-amd64-glibc.tar.xz
PACKAGE_PATH_AMD64_GLIBC: rockpass-${CI_COMMIT_TAG}-linux-amd64-glibc
PACKAGE_NAME_AMD64_MUSL: rockpass-${CI_COMMIT_TAG}-linux-amd64-musl.tar.xz
PACKAGE_PATH_AMD64_MUSL: rockpass-${CI_COMMIT_TAG}-linux-amd64-musl
PACKAGE_NAME_AMD64_STATIC: rockpass-${CI_COMMIT_TAG}-linux-amd64-static.tar.xz
PACKAGE_PATH_AMD64_STATIC: rockpass-${CI_COMMIT_TAG}-linux-amd64-static
PACKAGE_NAME_ARM64: rockpass-${CI_COMMIT_TAG}-linux-arm64.tar.xz
PACKAGE_PATH_ARM64: rockpass-${CI_COMMIT_TAG}-linux-arm64

Expand All @@ -25,7 +25,7 @@ stages:

Test AMD64 glibc:
stage: Test
image: rust:buster
image: rust:bookworm
script:
- cargo test
cache:
Expand All @@ -35,7 +35,7 @@ Test AMD64 glibc:

Build AMD64 glibc:
stage: Build
image: rust:buster
image: rust:bookworm
script:
- cargo build --release --locked
artifacts:
Expand All @@ -47,20 +47,18 @@ Build AMD64 glibc:
paths:
- target

Build AMD64 musl:
Build AMD64 static:
stage: Build
image: rust:alpine
variables:
RUSTFLAGS: -Ctarget-feature=-crt-static
script:
- apk -U --no-progress add libc-dev sqlite-dev
- apk -U --no-progress add musl-dev sqlite-dev sqlite-static
- cargo build --release --locked
artifacts:
name: ${ARTIFACTS_AMD64_MUSL}
name: ${ARTIFACTS_AMD64_STATIC}
paths:
- target/release/rockpass
cache:
key: ${CI_COMMIT_REF_SLUG}-amd64-musl
key: ${CI_COMMIT_REF_SLUG}-amd64-static
paths:
- target

Expand Down Expand Up @@ -99,19 +97,19 @@ Archive AMD64 glibc:
rules:
- if: $CI_COMMIT_TAG == null && $CI_PIPELINE_SOURCE != "merge_request_event"

Archive AMD64 musl:
Archive AMD64 static:
stage: Archive
script:
- install -Dm755 "target/release/rockpass" "${ARTIFACTS_AMD64_MUSL}/rockpass"
- install -Dm644 "rockpass.toml.example" "${ARTIFACTS_AMD64_MUSL}/rockpass.toml.example"
- install -Dm644 "README.md" "${ARTIFACTS_AMD64_MUSL}/README.md"
- install -Dm644 "LICENSE" "${ARTIFACTS_AMD64_MUSL}/LICENSE"
- install -Dm755 "target/release/rockpass" "${ARTIFACTS_AMD64_STATIC}/rockpass"
- install -Dm644 "rockpass.toml.example" "${ARTIFACTS_AMD64_STATIC}/rockpass.toml.example"
- install -Dm644 "README.md" "${ARTIFACTS_AMD64_STATIC}/README.md"
- install -Dm644 "LICENSE" "${ARTIFACTS_AMD64_STATIC}/LICENSE"
artifacts:
name: ${ARTIFACTS_AMD64_MUSL}
name: ${ARTIFACTS_AMD64_STATIC}
paths:
- ${ARTIFACTS_AMD64_MUSL}/
- ${ARTIFACTS_AMD64_STATIC}/
needs:
- Build AMD64 musl
- Build AMD64 static
rules:
- if: $CI_COMMIT_TAG == null && $CI_PIPELINE_SOURCE != "merge_request_event"

Expand Down Expand Up @@ -149,21 +147,21 @@ Package AMD64 glibc:
rules:
- if: $CI_COMMIT_TAG && $CI_PROJECT_ID == "43241571"

Package AMD64 musl:
Package AMD64 static:
stage: Package
script:
- apk -U --no-progress add xz
- install -Dm755 "target/release/rockpass" "${PACKAGE_PATH_AMD64_MUSL}/rockpass"
- install -Dm644 "rockpass.toml.example" "${PACKAGE_PATH_AMD64_MUSL}/rockpass.toml.example"
- install -Dm644 "README.md" "${PACKAGE_PATH_AMD64_MUSL}/README.md"
- install -Dm644 "LICENSE" "${PACKAGE_PATH_AMD64_MUSL}/LICENSE"
- tar cvJf "${PACKAGE_NAME_AMD64_MUSL}" "${PACKAGE_PATH_AMD64_MUSL}"
- install -Dm755 "target/release/rockpass" "${PACKAGE_PATH_AMD64_STATIC}/rockpass"
- install -Dm644 "rockpass.toml.example" "${PACKAGE_PATH_AMD64_STATIC}/rockpass.toml.example"
- install -Dm644 "README.md" "${PACKAGE_PATH_AMD64_STATIC}/README.md"
- install -Dm644 "LICENSE" "${PACKAGE_PATH_AMD64_STATIC}/LICENSE"
- tar cvJf "${PACKAGE_NAME_AMD64_STATIC}" "${PACKAGE_PATH_AMD64_STATIC}"
artifacts:
name: ${ARTIFACTS_AMD64_MUSL}
name: ${ARTIFACTS_AMD64_STATIC}
paths:
- ${PACKAGE_NAME_AMD64_MUSL}
- ${PACKAGE_NAME_AMD64_STATIC}
needs:
- Build AMD64 musl
- Build AMD64 static
rules:
- if: $CI_COMMIT_TAG && $CI_PROJECT_ID == "43241571"

Expand Down Expand Up @@ -203,7 +201,7 @@ Build and publish branch Docker image:
rules:
- if: $CI_COMMIT_TAG == null && $CI_PROJECT_ID == "43241571" && $CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_REF_PROTECTED == "true"
needs:
- Build AMD64 musl
- Build AMD64 static

Build and publish release Docker image:
stage: Docker
Expand Down Expand Up @@ -248,7 +246,7 @@ Build and publish release Docker image:
rules:
- if: $CI_COMMIT_TAG && $CI_PROJECT_ID == "43241571"
needs:
- Build AMD64 musl
- Build AMD64 static

Publish release:
stage: Publish
Expand All @@ -257,7 +255,7 @@ Publish release:
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${PACKAGE_NAME_AMD64_GLIBC} "${PACKAGE_REGISTRY_URL}/${PACKAGE_NAME_AMD64_GLIBC}"
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${PACKAGE_NAME_AMD64_MUSL} "${PACKAGE_REGISTRY_URL}/${PACKAGE_NAME_AMD64_MUSL}"
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${PACKAGE_NAME_AMD64_STATIC} "${PACKAGE_REGISTRY_URL}/${PACKAGE_NAME_AMD64_STATIC}"
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${PACKAGE_NAME_ARM64} "${PACKAGE_REGISTRY_URL}/${PACKAGE_NAME_ARM64}"
rules:
Expand All @@ -269,7 +267,7 @@ Release:
script: |
release-cli create --name "Release ${CI_COMMIT_TAG}" --tag-name ${CI_COMMIT_TAG} \
--assets-link "{\"name\":\"${PACKAGE_NAME_AMD64_GLIBC}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${PACKAGE_NAME_AMD64_GLIBC}\"}" \
--assets-link "{\"name\":\"${PACKAGE_NAME_AMD64_MUSL}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${PACKAGE_NAME_AMD64_MUSL}\"}" \
--assets-link "{\"name\":\"${PACKAGE_NAME_AMD64_STATIC}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${PACKAGE_NAME_AMD64_STATIC}\"}" \
--assets-link "{\"name\":\"${PACKAGE_NAME_ARM64}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${PACKAGE_NAME_ARM64}\"}"
rules:
- if: $CI_COMMIT_TAG && $CI_PROJECT_ID == "43241571"
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ ARG ALPINE_VERSION=latest

FROM alpine:${ALPINE_VERSION}
RUN adduser -S -D -H -h /var/lib/rockpass -s /sbin/nologin -G users -g rockpass rockpass && \
apk -U --no-progress add libgcc sqlite-libs && \
install -d -m0755 -o100 -g100 /var/lib/rockpass && \
rm -f /var/cache/apk/*
install -d -m0755 -o100 -g100 /var/lib/rockpass
COPY target/release/rockpass /bin/rockpass
EXPOSE 8000
ENV ROCKPASS_DATABASES="{rockpass={url=\"/var/lib/rockpass/rockpass.sqlite\"}}" \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ learn how to create your first user.
### With Docker

You can download a Rockpass Docker image from [here][glcr], from [Docker
Hub][hub] or from [Quay][quay] (only `linux-amd64-musl`).
Hub][hub] or from [Quay][quay] (only `linux-amd64`).

To run it, simply exec.
```
Expand Down

0 comments on commit 60d9a78

Please sign in to comment.