Skip to content

Commit

Permalink
add dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Joeyh021 committed May 17, 2023
1 parent 5126c0b commit 3f23f3c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]

0 comments on commit 3f23f3c

Please sign in to comment.