Skip to content

Commit

Permalink
Refactor github actions (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
robatipoor committed Jan 25, 2024
1 parent b15e265 commit 817ce0a
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
Expand All @@ -24,7 +24,7 @@ jobs:

- name: Cache dependencies
id: cache-dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-formater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: cargo fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: cargo clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/image-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
security_audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/spell-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check spelling
uses: crate-ci/typos@master
6 changes: 3 additions & 3 deletions .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
APP_PROFILE: test
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
Expand All @@ -46,7 +46,7 @@ jobs:
override: true

- name: Cache tarpaulin
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-tarpaulin
with:
path: |
Expand All @@ -71,7 +71,7 @@ jobs:
./scripts/init_mockserver.sh
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Generate code coverage
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ jobs:
APP_PROFILE: test
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache dependencies
id: cache-dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
Expand Down
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
# build stage
FROM rust:latest as builder

WORKDIR /workspace

RUN apt-get update && apt-get install lld clang -y

COPY . .

RUN cargo build --release

# deploy stage
FROM debian:bullseye-slim
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends openssl ca-certificates && apt-get clean

# create workspace directory
WORKDIR /workspace

COPY static static

COPY settings settings

# copy binary and configuration files
COPY --from=builder /workspace/target/release/app .

# expose port
EXPOSE 8080

ENV APP_PROFILE prod

ENV RUST_LOG info

# run the binary
ENTRYPOINT ["./app"]
4 changes: 2 additions & 2 deletions src/constant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ pub static EMAIL: Lazy<EmailClient> =
Lazy::new(|| EmailClient::build_from_config(&CONFIG).unwrap());
pub const MAX_RETRY: u32 = 10;
pub const MINIMUM_DELAY_TIME: std::time::Duration = std::time::Duration::from_millis(100);
pub static REFERESH_TOKEN_ENCODE_KEY: Lazy<EncodingKey> = Lazy::new(|| {
pub static REFRESH_TOKEN_ENCODE_KEY: Lazy<EncodingKey> = Lazy::new(|| {
let key = CONFIG.secret.read_private_refresh_key().unwrap();
EncodingKey::from_rsa_pem(key.as_bytes()).unwrap()
});
pub static REFERESH_TOKEN_DECODE_KEY: Lazy<DecodingKey> = Lazy::new(|| {
pub static REFRESH_TOKEN_DECODE_KEY: Lazy<DecodingKey> = Lazy::new(|| {
let key = CONFIG.secret.read_public_refresh_key().unwrap();
DecodingKey::from_rsa_pem(key.as_bytes()).unwrap()
});
Expand Down
4 changes: 2 additions & 2 deletions src/service/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn info(
}

pub async fn refresh(state: &AppState, req: RefreshTokenRequest) -> AppResult<TokenResponse> {
let user_claims = UserClaims::decode(&req.token, &REFERESH_TOKEN_DECODE_KEY)?.claims;
let user_claims = UserClaims::decode(&req.token, &REFRESH_TOKEN_DECODE_KEY)?.claims;
info!("Refresh token: {user_claims:?}");
let user_id = service::session::check(&state.redis, &user_claims).await?;
let user = crate::repo::user::find_by_id(&*state.db, user_id)
Expand All @@ -47,7 +47,7 @@ pub fn generate_tokens(
let access_token = UserClaims::new(EXPIRE_BEARER_TOKEN_SECS, user_id, session_id, role)
.encode(&ACCESS_TOKEN_ENCODE_KEY)?;
let refresh_token = UserClaims::new(EXPIRE_REFRESH_TOKEN_SECS, user_id, session_id, role)
.encode(&REFERESH_TOKEN_ENCODE_KEY)?;
.encode(&REFRESH_TOKEN_ENCODE_KEY)?;
Ok(TokenResponse::new(
access_token,
refresh_token,
Expand Down
3 changes: 1 addition & 2 deletions src/util/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use axum_extra::{
TypedHeader,
};

use async_trait::async_trait;
use axum::extract::FromRequestParts;
use axum::http::request::Parts;
use axum::RequestPartsExt;
Expand Down Expand Up @@ -64,7 +63,7 @@ impl UserClaims {
}
}

#[async_trait]
#[async_trait::async_trait]
impl FromRequestParts<AppState> for UserClaims {
type Rejection = AppError;

Expand Down

0 comments on commit 817ce0a

Please sign in to comment.