Skip to content

Commit

Permalink
test6
Browse files Browse the repository at this point in the history
  • Loading branch information
johndeniel committed Jun 10, 2024
1 parent e944988 commit 152befe
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 76 deletions.
52 changes: 14 additions & 38 deletions .github/workflows/build-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,30 @@
name: Docker Hub Deployment

on:
push:
branches:
- main

jobs:
build:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: pulling git repo
- name: Checkout repository
uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Build and test code
run: |
cargo build --verbose
cargo test --verbose

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
context: .
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/skylark:build-v1.001
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: |
RUST_BACKTRACE=1
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
tags: ${{ secrets.DOCKER_USERNAME }}/spotify:latest
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "logging"
name = "spotify"
version = "0.1.0"
edition = "2021"

Expand Down
44 changes: 21 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
FROM messense/rust-musl-cross:x86_64-musl as chef
RUN cargo install cargo-chef
WORKDIR /logging
# Use the official Rust image as the base image
FROM rust:latest AS builder

FROM chef AS planner
# Copy source code from previous stage
COPY . .
# Generate info for caching dependencies
RUN cargo chef prepare --recipe-path recipe.json
# Create a new empty shell project
RUN USER=root cargo new --bin spotify
WORKDIR /spotify

FROM chef AS builder
COPY --from=planner /logging/recipe.json recipe.json
# Enable backtrace for better error logs
ENV RUST_BACKTRACE=1
# Build & cache dependencies
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
# Copy source code from previous stage
COPY . .
# Build application
RUN cargo build --release --target x86_64-unknown-linux-musl
# Copy the Cargo.toml and Cargo.lock files
COPY Cargo.toml Cargo.lock ./

# Create a new stage with a minimal image
FROM scratch
COPY --from=builder /logging/target/x86_64-unknown-linux-musl/release/logging /logging
ENTRYPOINT ["/logging"]
EXPOSE 7860
# Copy the source code
COPY src ./src

# Build the application in release mode
RUN cargo build --release

# Use the official Debian image as the base image for the runtime
FROM debian:buster-slim

# Copy the compiled binary from the builder stage
COPY --from=builder /spotify/target/release/spotify /usr/local/bin/spotify

# Run the application
CMD ["spotify"]
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use logging::run;
use spotify::run;

#[tokio::main]
async fn main() {
Expand Down

0 comments on commit 152befe

Please sign in to comment.