diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8b48209 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,217 @@ +name: Release + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + workflow_call: + secrets: + DOCKER_PASSWORD: + required: true + +permissions: + contents: write + +env: + PROJECT_NAME: rustyhogs + +jobs: + dist-binaries: + name: Dist Binaries + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + build: [x86_64-linux, x86_64-macos, x86_64-windows] + include: + - build: x86_64-linux + os: ubuntu-latest + rust: stable + target: x86_64-unknown-linux-gnu + cross: false + - build: x86_64-macos + os: macos-latest + rust: stable + target: x86_64-apple-darwin + cross: false + # - build: aarch64-macos + # os: macos-13-xlarge + # rust: stable + # target: aarch64-apple-darwin + # cross: false + - build: x86_64-windows + os: windows-2019 + rust: stable + target: x86_64-pc-windows-msvc + cross: false + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Install ${{ matrix.rust }}-${{ matrix.target }} toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + target: ${{ matrix.target }} + override: true + - name: Build release binaries + uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.cross }} + command: build + args: --release --target ${{ matrix.target }} + - name: Build archive + shell: bash + run: | + mkdir dist + ls -lah target/${{ matrix.target }}/release + if [[ ${{ matrix.build }} =~ "windows" ]]; then + echo "${{ matrix.build }}: using .exe extension" + exe=".exe" + fi + cp ./target/${{ matrix.target }}/release/*_hog$exe dist + - uses: actions/upload-artifact@v3 + with: + name: bins-${{ matrix.build }} + path: dist + dist-lambda: + name: Dist Lambda + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Install stable-x86_64-unknown-linux-musl toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + target: x86_64-unknown-linux-musl + override: true + - name: Build release binaries + uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --release --target x86_64-unknown-linux-musl + - name: Build archive + shell: bash + run: | + mkdir dist + cp ./target/x86_64-unknown-linux-musl/release/*_lambda dist + - uses: actions/upload-artifact@v3 + with: + name: bins-lambda + path: dist + dist-docker: + name: Dist Docker + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Get tag name + id: tagname + run: | + name=dev + echo $GITHUB_REF + if [[ $GITHUB_REF == refs/tags/v* ]]; then + name=${GITHUB_REF:10} + fi + echo "tag=${name//v}" >> "$GITHUB_OUTPUT" + - name: Build Docker Images + shell: bash + run: make docker-build VERSION=${{ steps.tagname.outputs.tag }} + - name: Save Docker Images + shell: bash + run: make docker-save VERSION=${{ steps.tagname.outputs.tag }} + - uses: actions/upload-artifact@v3 + with: + name: docker + path: images.tar + publish: + name: Publish Archive + needs: [dist-binaries, dist-lambda, dist-docker] + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Download artifacts + uses: actions/download-artifact@v3 + - name: List binaries + run: ls -lah bins-* + - name: Get tag name + id: tagname + run: | + name=dev + echo $GITHUB_REF + if [[ $GITHUB_REF == refs/tags/v* ]]; then + name=${GITHUB_REF:10} + fi + echo "tagname=${name}" >> "$GITHUB_OUTPUT" + echo "tag=${name//v}" >> "$GITHUB_OUTPUT" + - name: Build archive + shell: bash + run: | + set -ex + rm -rf tmp + mkdir tmp + mkdir dist + for dir in bins-*; + do + platform=${dir#"bins-"} + pkgname=$PROJECT_NAME-${{ steps.tagname.outputs.tag }}-$platform + ls -lah $dir + chmod +x $dir/* + mkdir tmp/$pkgname + mv $dir/* tmp/$pkgname + if [[ $platform =~ "windows" ]]; then + (cd tmp && zip -r ../dist/$pkgname.zip $pkgname) + else + tar czf dist/$pkgname.tar.gz -C tmp $pkgname + fi + done + - name: Add scripts to archive + shell: bash + run: | + pkgname=$PROJECT_NAME-${{ steps.tagname.outputs.tag }}-scripts + tar czf dist/$pkgname.tar.gz scripts + - name: Release archive + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: dist/* + file_glob: true + tag: ${{ steps.tagname.outputs.tagname }} + overwrite: true + publish-docker: + name: Publish Docker Images + needs: [dist-binaries, dist-lambda, dist-docker] + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: docker + - name: Load Docker Images + shell: bash + run: make docker-load + - name: List Docker Images + shell: bash + run: docker images | grep hog + - name: Get tag name + id: tagname + run: | + name=dev + echo $GITHUB_REF + if [[ $GITHUB_REF == refs/tags/v* ]]; then + name=${GITHUB_REF:10} + fi + echo "tag=${name//v}" >> "$GITHUB_OUTPUT" + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: wetfeet2000 + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Publish Docker Images + run: make docker-publish VERSION=${{ steps.tagname.outputs.tag }} diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..de7d794 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,71 @@ +name: Testing + +on: + pull_request: + branches: [master] + +env: + CARGO_TERM_COLOR: always + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Compile Check + run: cargo check + - name: Format check + run: cargo fmt --all --check + - name: Lint + run: cargo clippy + test: + name: Test + needs: lint + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + build: [x86_64-linux, x86_64-linux-musl, x86_64-macos, x86_64-windows] + include: + - build: x86_64-linux + os: ubuntu-latest + rust: stable + target: x86_64-unknown-linux-gnu + cross: false + - build: x86_64-linux-musl + os: ubuntu-latest + rust: stable + target: x86_64-unknown-linux-musl + cross: true + - build: x86_64-macos + os: macos-latest + rust: stable + target: x86_64-apple-darwin + cross: false + # - build: aarch64-macos + # os: macos-13-xlarge + # rust: stable + # target: aarch64-apple-darwin + # cross: false + - build: x86_64-windows + os: windows-2019 + rust: stable + target: x86_64-pc-windows-msvc + cross: false + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Install ${{ matrix.rust }}-${{ matrix.target }} toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + target: ${{ matrix.target }} + override: true + - name: Test + uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.cross }} + command: test + args: --release --target ${{ matrix.target }} --verbose diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0224b36..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: rust -rust: - - stable - - beta - - nightly -jobs: - allow_failures: - - rust: nightly - fast_finish: true -cache: cargo -os: osx -script: - - cargo build --release --verbose diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index cfbb092..0000000 --- a/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -ARG RUST_VERSION=1.51 -FROM rust:${RUST_VERSION} as builder -RUN mkdir -p /build -WORKDIR /build -COPY . /build/ -RUN cargo build --release - -FROM debian:buster-slim -ARG HOG="choctaw" -ENV HOG_BIN="${HOG}_hog" -RUN apt-get update && apt-get install -y openssl openssh-client ca-certificates -COPY --from=builder /build/target/release/*_hog /usr/local/bin/ -ENV PATH=/usr/local/bin:$PATH -COPY ./entrypoint.sh /usr/local/bin -RUN chmod +x /usr/local/bin/entrypoint.sh -ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/Dockerfile.build b/Dockerfile.build new file mode 100644 index 0000000..5d046e9 --- /dev/null +++ b/Dockerfile.build @@ -0,0 +1,5 @@ +FROM rust:latest +RUN mkdir -p /build +WORKDIR /build +COPY . /build/ +RUN cargo build --release diff --git a/Dockerfile.hog b/Dockerfile.hog new file mode 100644 index 0000000..4717acd --- /dev/null +++ b/Dockerfile.hog @@ -0,0 +1,6 @@ +FROM rust-builder as builder +FROM debian:bookworm-slim +ARG HOG="choctaw" +ENV HOG_BIN="${HOG}_hog" +COPY --from=builder /build/target/release/$HOG_BIN /usr/local/bin/ +ENTRYPOINT /usr/local/bin/$HOG_BIN diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c876a36 --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +null: + @: + +docker-build: check-version + @echo Building Rusty Hogs version: $(VERSION) + docker build --tag rust-builder -f Dockerfile.build . + docker build --tag wetfeet2000/ankamali_hog:$(VERSION) --build-arg HOG=ankamali -f Dockerfile.hog . + docker build --tag wetfeet2000/berkshire_hog:$(VERSION) --build-arg HOG=berkshire -f Dockerfile.hog . + docker build --tag wetfeet2000/choctaw_hog:$(VERSION) --build-arg HOG=choctaw -f Dockerfile.hog . + docker build --tag wetfeet2000/duroc_hog:$(VERSION) --build-arg HOG=duroc -f Dockerfile.hog . + docker build --tag wetfeet2000/essex_hog:$(VERSION) --build-arg HOG=essex -f Dockerfile.hog . + docker build --tag wetfeet2000/gottingen_hog:$(VERSION) --build-arg HOG=gottingen -f Dockerfile.hog . + docker build --tag wetfeet2000/hante_hog:$(VERSION) --build-arg HOG=hante -f Dockerfile.hog . + +docker-save: check-version + docker image save -o images.tar \ + wetfeet2000/ankamali_hog:$(VERSION) \ + wetfeet2000/berkshire_hog:$(VERSION) \ + wetfeet2000/choctaw_hog:$(VERSION) \ + wetfeet2000/duroc_hog:$(VERSION) \ + wetfeet2000/essex_hog:$(VERSION) \ + wetfeet2000/gottingen_hog:$(VERSION) \ + wetfeet2000/hante_hog:$(VERSION) + +docker-load: + docker load -i images.tar + +docker-publish: check-version + docker push wetfeet2000/ankamali_hog:$(VERSION) + docker push wetfeet2000/berkshire_hog:$(VERSION) + docker push wetfeet2000/choctaw_hog:$(VERSION) + docker push wetfeet2000/duroc_hog:$(VERSION) + docker push wetfeet2000/essex_hog:$(VERSION) + docker push wetfeet2000/gottingen_hog:$(VERSION) + docker push wetfeet2000/hante_hog:$(VERSION) + +check-version: + @if test ! $(VERSION); then echo "VERSION is undefined"; exit 1; fi diff --git a/build_docker.sh b/build_docker.sh deleted file mode 100755 index 07b6684..0000000 --- a/build_docker.sh +++ /dev/null @@ -1,14 +0,0 @@ -docker system prune -a -cargo clean -docker build --tag wetfeet2000/ankamali_hog:$1 --build-arg HOG=ankamali . -docker push wetfeet2000/ankamali_hog:$1 -docker build --tag wetfeet2000/berkshire_hog:$1 --build-arg HOG=berkshire . -docker push wetfeet2000/berkshire_hog:$1 -docker build --tag wetfeet2000/choctaw_hog:$1 --build-arg HOG=choctaw . -docker push wetfeet2000/choctaw_hog:$1 -docker build --tag wetfeet2000/duroc_hog:$1 --build-arg HOG=duroc . -docker push wetfeet2000/duroc_hog:$1 -docker build --tag wetfeet2000/essex_hog:$1 --build-arg HOG=essex . -docker push wetfeet2000/essex_hog:$1 -docker build --tag wetfeet2000/gottingen_hog:$1 --build-arg HOG=gottingen . -docker push wetfeet2000/gottingen_hog:$1 diff --git a/build_ghrelease.sh b/build_ghrelease.sh deleted file mode 100755 index f893736..0000000 --- a/build_ghrelease.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -if [[ $(uname) != "Darwin" ]]; then - echo "script currently designed to build for macs and musl" - exit 1 -fi - -cargo build --release -if [ $? -ne 0 ]; then - echo "cargo build returned non-zero exit code" - exit 1 -fi - -docker run --rm -it -v "$(pwd)":/home/rust/src ekidd/rust-musl-builder cargo build --release -if [ $? -ne 0 ]; then - echo "cross build returned non-zero exit code" - exit 1 -fi - -cp target/x86_64-unknown-linux-musl/release/berkshire_hog_lambda bootstrap -zip -j berkshire_lambda.zip bootstrap -mkdir darwin_releases -mkdir musl_releases -cp target/release/*_hog darwin_releases -cp target/x86_64-unknown-linux-musl/release/*_hog musl_releases -mv scripts/.idea ../ -strip darwin_releases/* -for f in darwin_releases/*; do -ft=$(echo $f | awk -F/ '{print $2}'); -zip -r rustyhogs-darwin-$ft-1.0.11.zip $f; -done -for f in musl_releases/*; do -ft=$(echo $f | awk -F/ '{print $2}'); -zip -r rustyhogs-musl-$ft-1.0.11.zip $f; -done -zip -r rustyhogs-lambda_$1.zip berkshire_lambda.zip -zip -r rustyhogs-scripts_$1.zip scripts -rm -rf darwin_releases musl_releases -mv ../.idea scripts -echo "Output build in release.zip" - diff --git a/build_lambda.sh b/build_lambda.sh deleted file mode 100755 index 65f2cbc..0000000 --- a/build_lambda.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/zsh - -cross build --release --target x86_64-unknown-linux-musl -cp target/x86_64-unknown-linux-musl/release/berkshire_hog_lambda bootstrap -zip -j berkshire_lambda.zip bootstrap diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 104b1f7..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -set -x - -"/usr/local/bin/${HOG_BIN}" "$@"