diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 137f3cb..e99e149 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,3 +24,43 @@ jobs: run: cargo clippy --verbose --workspace - name: Check formatting run: cargo fmt --check --verbose + + build-and-push-image: + name: Build and Push Docker Image + runs-on: ubuntu-latest + permissions: + packages: write + needs: + - lint + if: success() && github.ref_name == 'main' && github.event_name == 'push' + steps: + - uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get Docker Metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + tags: | # tag with commit hash and with 'latest' + type=sha + type=raw,value=latest,enable={{is_default_branch}} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and Push Docker image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b5be59c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM rust:1 as builder + +# create empty projects +RUN USER=root cargo new --bin go2 +WORKDIR /go2 + +# copy package manifest in +COPY Cargo.toml Cargo.lock /go2 + +# build to cache deps +RUN cargo build --release +RUN rm src/*.rs + +# copy source code in +COPY ./dcspkg-server/src ./src + +# build our code +RUN rm ./target/release/deps/dcspkg* +RUN cargo build --release + +# new base, slimmer, no toolchains +FROM debian:bullseye-slim +COPY --from=builder /dcspkg-server/target/release/dcspkg_server . + +CMD [ "./dcspkg_server" ] \ No newline at end of file