Skip to content

Commit

Permalink
Setup Docker CI
Browse files Browse the repository at this point in the history
  • Loading branch information
yanorei32 committed Aug 18, 2023
1 parent 27e3f73 commit 65487fa
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,48 @@ jobs:
files: |
nichijid-rs-windows.zip
nichijid-rs-linux.zip
- uses: docker/[email protected]

- uses: docker/[email protected]
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/[email protected]
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/[email protected]
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 }}
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 65487fa

Please sign in to comment.