diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b5df10a..ceb56a8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -116,3 +116,48 @@ jobs: files: | nichijid-rs-windows.zip nichijid-rs-linux.zip + + - uses: docker/setup-buildx-action@v2.9.1 + + - uses: docker/login-action@v2.2.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create tagname + id: tagname + run: | + VERSION="$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')" + # 2193: ${{ github.ref }} will replaced by GitHub Actions + # shellcheck disable=SC2193 + [[ "${{ github.ref }}" == refs/tags/* ]] && VERSION="${VERSION/v/}" + [[ "$VERSION" == "master" ]] && VERSION=latest + # shellcheck disable=SC2193 + [[ "${{ github.ref }}" == refs/pull/* ]] && VERSION=dontpush + echo "$VERSION" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + - name: Build and Push + uses: docker/build-push-action@v4.1.1 + if: "! startsWith(github.ref, 'refs/pull/')" + with: + context: . + platforms: linux/amd64 + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + tags: | + ghcr.io/yanorei32/nichijid-rs:${{ steps.tagname.outputs.version }} + + - name: Build and Push + uses: docker/build-push-action@v4.1.1 + if: "startsWith(github.ref, 'refs/pull/')" + with: + context: . + platforms: linux/amd64 + push: false + cache-from: type=gha + cache-to: type=gha,mode=max + tags: | + ghcr.io/yanorei32/nichijid-rs:${{ steps.tagname.outputs.version }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fbc6f64 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM rust:1.71.1 as build-env +LABEL maintainer="yanorei32" + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +WORKDIR /usr/src +RUN cargo new nichijid-rs +COPY LICENSE Cargo.toml Cargo.lock /usr/src/nichijid-rs/ +WORKDIR /usr/src/nichijid-rs +ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse +RUN cargo install cargo-license && cargo license \ + --authors \ + --do-not-bundle \ + --avoid-dev-deps \ + --avoid-build-deps \ + --filter-platform "$(rustc -vV | sed -n 's|host: ||p')" \ + > CREDITS + +RUN cargo build --release +COPY src/ /usr/src/nichijid-rs/src/ + +RUN touch src/* && cargo build --release + +FROM debian:bullseye-slim@sha256:5e8651093bdb71901c1c60bb95c1d35e0975e0a1a0c6207ca2662b675e2ec323 + +WORKDIR / + +COPY --chown=root:root --from=build-env \ + /usr/src/nichijid-rs/CREDITS \ + /usr/src/nichijid-rs/LICENSE \ + /usr/share/licenses/nichijid-rs/ + +COPY --chown=root:root --from=build-env \ + /usr/src/nichijid-rs/target/release/nichijid-rs \ + /usr/bin/nichijid-rs + +CMD ["/usr/bin/nichijid-rs"]