Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
sargon64 committed Jul 26, 2023
1 parent a1e5133 commit 7776d39
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
secret.key
.env
Cargo.lock
target/
10 changes: 5 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ jobs:
name: beatforge_api
runs-on: ubuntu-latest
steps:
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
Expand All @@ -22,11 +27,6 @@ jobs:
args: --release

# publish to ghcr.io and publish artifact
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v2
with:
context: .
Expand Down
12 changes: 11 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
FROM rust:latest

LABEL org.opencontainers.image.source=https://github.com/beat-forge/api

WORKDIR /app

COPY . .

RUN cargo build --release

CMD ["./target/release/gql-api"]
RUN mv ./target/release/gql-api .

RUN rm -rf ./target

EXPOSE 8080

CMD ["./gql-api"]
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ pub struct Key([u8; 1024]);

lazy_static::lazy_static! {
pub static ref KEY: Arc<Key> = {
if !Path::new("./secret.key").exists() {
if !Path::new("./data/secret.key").exists() {
let _ = std::fs::create_dir(Path::new("./data"));
let mut rng = rand::thread_rng();
let key: Vec<u8> = (0..1024).map(|_| rng.gen::<u8>()).collect();
std::fs::write("./secret.key", key).unwrap();
std::fs::write("./data/secret.key", key).unwrap();

println!("Generated secret key (first run)");
}

Arc::new(Key(std::fs::read("./secret.key").unwrap().try_into().unwrap()))
Arc::new(Key(std::fs::read("./data/secret.key").unwrap().try_into().unwrap()))
};
}

Expand Down

0 comments on commit 7776d39

Please sign in to comment.