Skip to content

Commit 3e78c5e

Browse files
author
vsilent
committed
Remove unused imports, list docker containers added
1 parent 7c25842 commit 3e78c5e

File tree

10 files changed

+55
-40
lines changed

10 files changed

+55
-40
lines changed

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ edition = "2018"
88
features = ["openssl", "rustls", "compress", "secure-cookies"]
99

1010
[dependencies]
11-
actix-web = { version = "3.0.0-beta.3", features=["rustls"] }
11+
bollard = "0.11"
12+
actix-web = { version = "3.3.3", features=["rustls"] }
1213
actix-rt = "2.1.0"
13-
actix-service = "2.0.0"
14-
actix-cors = "0.5.4"
14+
actix-service = "1.0.6"
15+
actix-cors = "0.3.0"
1516
actix-http = "2.1.0"
16-
actix = "0.12"
17+
#actix = "0.12"
1718
log = "0.4.11"
1819
env_logger = "0.9.0"
1920
serde = "1.0.116"

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ services:
99
build:
1010
context: .
1111
dockerfile: docker/local/Dockerfile
12-
entrypoint: [ 'bash', '-c', 'sleep infinity' ]
12+
# entrypoint: [ 'bash', '-c', 'sleep infinity' ]
1313
# restart: always
1414
ports:
15-
- "5000:5000"
15+
- "5003:5000"
1616
env_file: .env
1717
volumes:
1818
- db:/app/db

docker/local/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ WORKDIR /app
1111
# copy manifests
1212
COPY ./Cargo.toml ./Cargo.toml
1313

14+
COPY ./migrations /app/migrations
15+
1416
# build this project to cache dependencies
1517
RUN cargo build --release; \
1618
rm src/*.rs
@@ -34,7 +36,7 @@ WORKDIR /app
3436

3537
# install libpq
3638
RUN apt-get update; \
37-
apt-get install --no-install-recommends -y libpq-dev; \
39+
apt-get install --no-install-recommends -y libpq-dev sqlite3 libsqlite3-dev; \
3840
rm -rf /var/lib/apt/lists/*
3941

4042
# copy binary and configuration files
@@ -43,7 +45,7 @@ COPY --from=build /app/.env .
4345

4446
# expose port
4547
EXPOSE 5000
46-
48+
RUN mkdir /app/db
4749
RUN /usr/bin/sqlite3 /app/db/stackdog.db
4850

4951
# run the binary

docker/prod/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ RUN apt-get update; \
1313
# copy binary and configuration files
1414
COPY ./stackdog .
1515
COPY ./.env .
16-
16+
COPY ./migrations .
1717
# expose port
1818
EXPOSE 5000
1919

2020
# run the binary
21-
ENTRYPOINT ["/app/stackdog"]
21+
ENTRYPOINT ["/app/stackdog"]

src/api/docker_controller.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
use crate::{
2-
config::db::Pool,
3-
constants,
4-
models::{
5-
response::ResponseBody,
6-
},
7-
services::docker_service,
2+
constants, models::response::ResponseBody, services::docker_service,
83
};
9-
use actix_web::{web, HttpRequest, HttpResponse, Result};
4+
use actix_web::{HttpResponse, Result};
105

11-
pub async fn find_all(pool: web::Data<Pool>) -> Result<HttpResponse> {
12-
match docker_service::find_all(&pool) {
13-
Ok(message) => Ok(HttpResponse::Ok().json(ResponseBody::new(&message, constants::EMPTY))),
6+
pub async fn find_all() -> Result<HttpResponse> {
7+
match docker_service::find_all().await {
8+
Ok(message) => Ok(HttpResponse::Ok().json(
9+
ResponseBody::new(constants::EMPTY, &message))),
1410
Err(err) => Ok(err.response()),
1511
}
1612
}

src/config/db.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ use diesel::{
77
};
88
use crate::schema::users::columns::updated_at;
99
use chrono::Utc;
10-
use diesel::connection::SimpleConnection;
11-
use crate::schema::users::dsl::users;
12-
use diesel::RunQueryDsl;
1310

1411
embed_migrations!();
1512

src/constants.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Messages
2-
pub const MESSAGE_OK: &str = "ok";
32
pub const MESSAGE_LOGIN_SUCCESS: &str = "Login successfully";
43
pub const MESSAGE_LOGIN_FAILED: &str = "Wrong username or password, please try again";
54
pub const MESSAGE_USER_NOT_FOUND: &str = "User not found";

src/models/user.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{
2-
constants,
32
config::db::Connection,
43
models::{user_token::UserToken},
54
schema::users::{self, dsl::*},

src/services/docker_service.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1+
use std::collections::HashMap;
2+
use bollard::container::ListContainersOptions;
3+
use bollard::Docker;
4+
use serde_json;
5+
16
use crate::{
2-
error::ServiceError,
3-
config::db::Pool,
7+
error::ServiceError
48
};
59
use actix_web::{
6-
// http::{
7-
// StatusCode,
8-
// header::HeaderValue,
9-
// },
10-
web,
10+
http::{
11+
StatusCode,
12+
}
1113
};
1214

13-
pub fn find_all(pool: &web::Data<Pool>) -> Result<String, ServiceError> {
14-
// docker
15-
// Here we need to discuss how to connect docker api
16-
// let docker = // docker api client;
17-
// match docker::find_all(&pool.get().unwrap()) {
18-
// Ok(message) => Ok(message),
19-
// Err(message) => Err(ServiceError::new(StatusCode::BAD_REQUEST, message))
15+
pub async fn find_all() -> Result<String, ServiceError> {
16+
let docker = Docker::connect_with_local_defaults().unwrap();
17+
let mut list_container_filters = HashMap::new();
18+
list_container_filters.insert("status", vec!["running"]);
19+
20+
let containers = &docker
21+
.list_containers(Some(ListContainersOptions {
22+
all: true,
23+
filters: list_container_filters,
24+
..Default::default()
25+
}))
26+
.await;
27+
// let c = containers.iter().collect::<String>();
28+
// let mut names = Vec::new();
29+
// for container in containers {
30+
// names.push(container.);
2031
// }
21-
unimplemented!()
32+
match containers {
33+
Err(_)=> Err(ServiceError::new(StatusCode::NO_CONTENT,
34+
"No containers found".to_string())),
35+
Ok(cs) => Ok(serde_json::to_string(cs).unwrap()),
36+
}
2237
}

web/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ OR
1414
`docker build . -t stackdog`
1515
`docker run -p8080:8080 stackdog`
1616

17+
## Test API
18+
19+
20+
21+
22+
1723
## Production build
1824

1925
`npm install`

0 commit comments

Comments
 (0)