diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +target diff --git a/.env b/.env index f2fc188..7062563 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -DATABASE_URL=postgresql://postgres:postgres@localhost:5432/tutors \ No newline at end of file +DATABASE_URL=postgres://postgres:postgres@db:5432/tutors diff --git a/.sqlx/query-4bb3a3bedf046c63aa3603295ed85bba8a04ed314f68a02dfc16e5659a1aa94a.json b/.sqlx/query-4bb3a3bedf046c63aa3603295ed85bba8a04ed314f68a02dfc16e5659a1aa94a.json new file mode 100644 index 0000000..90ba6aa --- /dev/null +++ b/.sqlx/query-4bb3a3bedf046c63aa3603295ed85bba8a04ed314f68a02dfc16e5659a1aa94a.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE\n public.posts\nSET\n md_file = $2\nWHERE\n md_file = $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Varchar" + ] + }, + "nullable": [] + }, + "hash": "4bb3a3bedf046c63aa3603295ed85bba8a04ed314f68a02dfc16e5659a1aa94a" +} diff --git a/.sqlx/query-5d0ca9699818962a1e5076a478a5d8b35e9f02934d5a5cfc9161bf6c61340462.json b/.sqlx/query-5d0ca9699818962a1e5076a478a5d8b35e9f02934d5a5cfc9161bf6c61340462.json new file mode 100644 index 0000000..1fe2e2e --- /dev/null +++ b/.sqlx/query-5d0ca9699818962a1e5076a478a5d8b35e9f02934d5a5cfc9161bf6c61340462.json @@ -0,0 +1,14 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM\n public.posts\nWHERE\n md_file = $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [] + }, + "hash": "5d0ca9699818962a1e5076a478a5d8b35e9f02934d5a5cfc9161bf6c61340462" +} diff --git a/.sqlx/query-d53fc0e6bd0d21841bccf63b0a0d02f83881cd2579a5bb20b5e98ff7f777b786.json b/.sqlx/query-d53fc0e6bd0d21841bccf63b0a0d02f83881cd2579a5bb20b5e98ff7f777b786.json new file mode 100644 index 0000000..2614302 --- /dev/null +++ b/.sqlx/query-d53fc0e6bd0d21841bccf63b0a0d02f83881cd2579a5bb20b5e98ff7f777b786.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE\n public.posts\nSET\n title = $2, description = $3\nWHERE\n md_file = $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Varchar", + "Varchar" + ] + }, + "nullable": [] + }, + "hash": "d53fc0e6bd0d21841bccf63b0a0d02f83881cd2579a5bb20b5e98ff7f777b786" +} diff --git a/Cargo.lock b/Cargo.lock index 4240df4..803ac41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "actix-codec" @@ -962,6 +962,27 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1153,7 +1174,7 @@ dependencies = [ "pest_derive", "serde", "serde_json", - "thiserror", + "thiserror 1.0.63", "walkdir", ] @@ -1162,18 +1183,25 @@ name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hashbrown" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" dependencies = [ - "ahash", "allocator-api2", + "equivalent", + "foldhash", ] [[package]] name = "hashlink" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" dependencies = [ - "hashbrown", + "hashbrown 0.15.4", ] [[package]] @@ -1308,7 +1336,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", ] [[package]] @@ -1399,11 +1427,10 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libsqlite3-sys" -version = "0.28.0" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c10584274047cb335c23d3e61bcef8e323adae7c5c8c760540f73610177fc3f" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" dependencies = [ - "cc", "pkg-config", "vcpkg", ] @@ -1514,12 +1541,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.7.4" @@ -1542,16 +1563,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "num-bigint-dig" version = "0.8.4" @@ -1626,12 +1637,47 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "openssl" +version = "0.10.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +dependencies = [ + "bitflags 2.6.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "300.5.1+3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "735230c832b28c000e3bc117119e6466a663ec73506bc0a9907ea4187508e42a" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.103" @@ -1640,6 +1686,7 @@ checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] @@ -1730,7 +1777,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95" dependencies = [ "memchr", - "thiserror", + "thiserror 1.0.63", "ucd-trie", ] @@ -2212,21 +2259,11 @@ dependencies = [ "der", ] -[[package]] -name = "sqlformat" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f895e3734318cc55f1fe66258926c9b910c124d47520339efecbb6c59cec7c1f" -dependencies = [ - "nom", - "unicode_categories", -] - [[package]] name = "sqlx" -version = "0.8.0" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27144619c6e5802f1380337a209d2ac1c431002dd74c6e60aebff3c506dc4f0c" +checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" dependencies = [ "sqlx-core", "sqlx-macros", @@ -2237,38 +2274,33 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.8.0" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a999083c1af5b5d6c071d34a708a19ba3e02106ad82ef7bbd69f5e48266b613b" +checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" dependencies = [ - "atoi", - "byteorder", + "base64 0.22.1", "bytes", "chrono", "crc", "crossbeam-queue", "either", "event-listener", - "futures-channel", "futures-core", "futures-intrusive", "futures-io", "futures-util", - "hashbrown", + "hashbrown 0.15.4", "hashlink", - "hex", "indexmap", "log", "memchr", "once_cell", - "paste", "percent-encoding", "serde", "serde_json", "sha2", "smallvec", - "sqlformat", - "thiserror", + "thiserror 2.0.12", "tokio", "tokio-stream", "tracing", @@ -2277,9 +2309,9 @@ dependencies = [ [[package]] name = "sqlx-macros" -version = "0.8.0" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a23217eb7d86c584b8cbe0337b9eacf12ab76fe7673c513141ec42565698bb88" +checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" dependencies = [ "proc-macro2", "quote", @@ -2290,9 +2322,9 @@ dependencies = [ [[package]] name = "sqlx-macros-core" -version = "0.8.0" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a099220ae541c5db479c6424bdf1b200987934033c2584f79a0e1693601e776" +checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" dependencies = [ "dotenvy", "either", @@ -2309,16 +2341,15 @@ dependencies = [ "sqlx-postgres", "sqlx-sqlite", "syn", - "tempfile", "tokio", "url", ] [[package]] name = "sqlx-mysql" -version = "0.8.0" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5afe4c38a9b417b6a9a5eeffe7235d0a106716495536e7727d1c7f4b1ff3eba6" +checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" dependencies = [ "atoi", "base64 0.22.1", @@ -2352,16 +2383,16 @@ dependencies = [ "smallvec", "sqlx-core", "stringprep", - "thiserror", + "thiserror 2.0.12", "tracing", "whoami", ] [[package]] name = "sqlx-postgres" -version = "0.8.0" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1dbb157e65f10dbe01f729339c06d239120221c9ad9fa0ba8408c4cc18ecf21" +checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" dependencies = [ "atoi", "base64 0.22.1", @@ -2373,7 +2404,6 @@ dependencies = [ "etcetera", "futures-channel", "futures-core", - "futures-io", "futures-util", "hex", "hkdf", @@ -2391,16 +2421,16 @@ dependencies = [ "smallvec", "sqlx-core", "stringprep", - "thiserror", + "thiserror 2.0.12", "tracing", "whoami", ] [[package]] name = "sqlx-sqlite" -version = "0.8.0" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2cdd83c008a622d94499c0006d8ee5f821f36c89b7d625c900e5dc30b5c5ee" +checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" dependencies = [ "atoi", "chrono", @@ -2416,6 +2446,7 @@ dependencies = [ "serde", "serde_urlencoded", "sqlx-core", + "thiserror 2.0.12", "tracing", "url", ] @@ -2445,9 +2476,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.73" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "837a7e8026c6ce912ff01cefbe8cafc2f8010ac49682e2a3d9decc3bce1ecaaf" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -2473,7 +2504,16 @@ version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.63", +] + +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl 2.0.12", ] [[package]] @@ -2487,6 +2527,17 @@ dependencies = [ "syn", ] +[[package]] +name = "thiserror-impl" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "time" version = "0.3.36" @@ -2636,6 +2687,7 @@ dependencies = [ "handlebars", "log", "markdown", + "openssl", "rand", "regex", "rs_sha512", @@ -2720,12 +2772,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" -[[package]] -name = "unicode_categories" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" - [[package]] name = "universal-hash" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 04ec537..bc2d9bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +openssl = {version = "0.10", features = ["vendored"]} actix-web="4" chrono = { version = "0.4.38", features = ["serde"] } #derive_more = "1.0.0" @@ -15,7 +16,7 @@ log = "0.4.22" markdown = "1.0.0-alpha.20" regex = "1.10.6" serde = { version = "1.0.206", features = ["derive"] } -sqlx = { version = "0.8.0", features = ["postgres", "runtime-tokio", "chrono"] } +sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio", "macros", "chrono"] } tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] } serde_json = "1.0.122" actix-session = { version = "0.10.0", features = ["cookie-session"] } diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d51cf6f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM rust:1.88.0-alpine3.22 as builder + +RUN apk add --no-cache musl-dev perl make pkgconfig + +WORKDIR /usr/src/app +ENV SQLX_OFFLINE=true +COPY Cargo.toml . +COPY Cargo.lock . + +RUN mkdir src && echo "fn main() {}" > src/main.rs +RUN cargo build --release --locked + +COPY . . +RUN touch src/main.rs +RUN cargo build --release --locked + +FROM scratch +WORKDIR /app +COPY --from=builder /usr/src/app/target/release/tutors /app/tutors +COPY --from=builder /usr/src/app/sql /app/sql +COPY static /app/static +COPY views /app/views + +CMD ["/app/tutors"] diff --git a/database/dump.sql b/database/dump.sql old mode 100644 new mode 100755 index a830cd8..cfff80a --- a/database/dump.sql +++ b/database/dump.sql @@ -16,20 +16,6 @@ SET xmloption = content; SET client_min_messages = warning; SET row_security = off; -ALTER TABLE ONLY public.sessions DROP CONSTRAINT session_users_id_fk; -DROP INDEX public.users_login_uindex; -DROP INDEX public.posts_title_index; -DROP INDEX public.posts_md_file_index; -ALTER TABLE ONLY public.users DROP CONSTRAINT users_pk; -ALTER TABLE ONLY public.sessions DROP CONSTRAINT session_pk; -ALTER TABLE ONLY public.posts DROP CONSTRAINT posts_pk; -ALTER TABLE public.users ALTER COLUMN id DROP DEFAULT; -ALTER TABLE public.posts ALTER COLUMN id DROP DEFAULT; -DROP SEQUENCE public.users_id_seq; -DROP TABLE public.users; -DROP TABLE public.sessions; -DROP SEQUENCE public.posts_id_seq; -DROP TABLE public.posts; SET default_tablespace = ''; SET default_table_access_method = heap; @@ -138,6 +124,7 @@ ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_ COPY public.users (id, login, name, password_hash) FROM stdin; 1 danilasar Даня bbc9c27f06c5275429f523e1a3955b9e33f1a90d88c19ef260da9e500494d6cf1f591d05afaedd64778329c63b023b12e5706e84de4972cfa82fbbc3fa66761d +2 gohy Иван a19502627632c6688cb1a3fa13eadeaf27abd6ae078554161afc238e214a4de72a48ce92b9276ad7c4d274677aed5b9a70b10348da686a1ab577dad9e8b820a2 \. @@ -211,4 +198,3 @@ ALTER TABLE ONLY public.sessions -- -- PostgreSQL database dump complete -- - diff --git a/docker-compose.yml b/docker-compose.yml index 006946a..cea2c19 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,27 +1,31 @@ -version: "3.9" - services: db: - image: postgres:16.2 - restart: always -# user: postgres + image: postgres:17.5 environment: - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=postgres - - POSTGRES_DB=kaluga + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=tutors + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 3s + retries: 5 ports: - - "5432:5432" + - "5432:5432" volumes: - - pgdata:/var/lib/postgresql/data - - ./database:/docker-entrypoint-initdb.d + - pgdata:/var/lib/postgresql/data + - ./database:/docker-entrypoint-initdb.d website: build: ./ restart: always - ports: - - "8080:80" depends_on: - - db + db: + condition: service_healthy + ports: + - "8080:8080" + environment: + - DATABASE_URL=postgres://postgres:postgres@db:5432/tutors volumes: - ./public:/public diff --git a/dockerfile b/dockerfile deleted file mode 100644 index 008d8e9..0000000 --- a/dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM rust:1.78.0 as builder - -WORKDIR /usr/src/app - -RUN rustup target add x86_64-unknown-linux-musl - -COPY Cargo.toml Cargo.lock ./ -COPY src src -COPY sql sql -COPY views views -COPY static static -RUN cargo build --target x86_64-unknown-linux-musl --release - -FROM scratch - -COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/tutors /usr/local/bin/tutors - -CMD ["tutors"] diff --git a/src/config.rs b/src/config.rs index 0beb292..de4494a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,10 +15,9 @@ fn default_port() -> u16 { } fn default_potgres_url() -> String { - "postgres://postgres:postgres@localhost/tutors".to_string() + "postgres://postgres:postgres@db/tutors".to_string() } fn default_host() -> String { - "127.0.0.1".to_string() + "0.0.0.0".to_string() } - diff --git a/views/index.hbs b/views/index.hbs index 0e0fe8c..f986b2a 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -21,4 +21,4 @@ -{{#if authored}}Выход{{/if}} \ No newline at end of file +{{#if authored}}Выход{{/if}}