diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..63d389d
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,68 @@
+name: Build and push docker image
+
+on:
+ workflow_call:
+ inputs:
+ DEPLOY_ENV:
+ description: 'The environment to deploy to'
+ required: true
+ type: string
+
+ RUST_VERSION:
+ description: The Rust version to use
+ required: true
+ type: string
+
+ IMAGE_NAME:
+ description: The name of the image to build
+ required: true
+ type: string
+
+ outputs:
+ DOCKER_IMAGE:
+ description: Name of Docker image
+ value: ${{ jobs.build-and-push-image.outputs.DOCKER_IMAGE }}
+
+env:
+ DOCKER_REGISTRY: ghcr.io
+ DOCKER_IMAGE: ${{ github.repository }}/${{ github.event.inputs.RUST_VERSION }}
+
+jobs:
+ build-and-push-image:
+ if: inputs.DEPLOY_ENV == 'production'
+ runs-on: ubuntu-latest
+
+ outputs:
+ DOCKER_IMAGE: ${{ steps.docker-meta.outputs.tags }}
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v2
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v3
+
+ - name: Log in to the container registry
+ uses: docker/login-action@v3
+ with:
+ registry: ${{ env.DOCKER_REGISTRY }}
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Docker meta-data
+ id: docker-meta
+ uses: docker/metadata-action@v3
+ with:
+ images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}:latest
+
+ - name: Build and push Docker image
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ push: true
+ build-args: |
+ RUST_VERSION=${{ inputs.RUST_VERSION }}
+ tags: ${{ steps.docker-meta.outputs.tags }}
+ labels: ${{ steps.docker-meta.outputs.labels }}
+ cache-from: type=registry,ref=user/app:latest
+ cache-to: type=inline
\ No newline at end of file
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index b600731..b7977dc 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -1,22 +1,22 @@
-name: CD
+name: Deploy app
on:
- workflow_run:
- workflows:
- - CI
- branches:
- - main
- types:
- - completed
+ workflow_call:
+ inputs:
+ DOCKER_IMAGE:
+ description: 'Path to the image'
+ required: true
+ type: string
jobs:
- CD:
- name: Deploy app
+ deploy-app:
runs-on: ubuntu-latest
+
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
-
- - run: flyctl deploy --remote-only
+ - run: |
+ flyctl deploy --remote-only --image ${{ env.DOCKER_IMAGE }}
env:
- FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
\ No newline at end of file
+ FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
+ DOCKER_IMAGE: ${{ github.event.inputs.DOCKER_IMAGE }}
\ No newline at end of file
diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml
new file mode 100644
index 0000000..edda6f0
--- /dev/null
+++ b/.github/workflows/linter.yml
@@ -0,0 +1,37 @@
+name: Lint project
+
+on:
+ workflow_call:
+ inputs:
+ RUST_VERSION:
+ description: Rust version to use for the workflow
+ type: string
+
+jobs:
+ lint-project:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Setup Rust environment
+ run: |
+ rustup update
+ rustup install ${{ inputs.RUST_VERSION }}
+ rustup default ${{ inputs.RUST_VERSION }}
+ rustup component add clippy
+
+ - name: Add WASM target
+ run: |
+ rustup target add wasm32-unknown-unknown
+
+ - name: Write toolchain info
+ run: |
+ cargo --version --verbose
+ rustc --version
+ cargo clippy --version
+
+ - name: Lint Rust code wiht Clippy
+ run: |
+ cargo clippy --all-targets --all-features --
\ No newline at end of file
diff --git a/.github/workflows/pipline.yml b/.github/workflows/pipline.yml
new file mode 100644
index 0000000..5d77599
--- /dev/null
+++ b/.github/workflows/pipline.yml
@@ -0,0 +1,38 @@
+name: Project ipeline
+
+on:
+ push:
+ branches:
+ - '**'
+ paths-ignore:
+ - 'LICENSE'
+ - 'README.md'
+ - 'CHANGELOG.md'
+
+jobs:
+ prepare:
+ uses: ./.github/workflows/prepare.yml
+ secrets: inherit
+
+ linter:
+ uses: ./.github/workflows/linter.yml
+ needs: [prepare]
+ secrets: inherit
+ with:
+ RUST_VERSION: ${{ needs.prepare.outputs.RUST_VERSION }}
+
+ build:
+ uses: ./.github/workflows/build.yml
+ needs: [prepare, linter]
+ secrets: inherit
+ with:
+ DEPLOY_ENV: ${{ needs.prepare.outputs.DEPLOY_ENV }}
+ RUST_VERSION: ${{ needs.prepare.outputs.RUST_VERSION }}
+ IMAGE_NAME: ${{ needs.prepare.outputs.IMAGE_NAME }}
+
+ deploy:
+ needs: [prepare, linter, build]
+ uses: ./.github/workflows/deploy.yml
+ secrets: inherit
+ with:
+ DOCKER_IMAGE: ${{ needs.build.outputs.DOCKER_IMAGE }}
diff --git a/.github/workflows/prepare.yml b/.github/workflows/prepare.yml
new file mode 100644
index 0000000..f396477
--- /dev/null
+++ b/.github/workflows/prepare.yml
@@ -0,0 +1,83 @@
+name: Prepare pipeline
+
+on:
+ workflow_call:
+ outputs:
+ DEPLOY_ENV:
+ description: What kind of deployment this is
+ value: ${{ jobs.prepare-pipeline.outputs.DEPLOY_ENV }}
+
+ RUST_VERSION:
+ description: The version of Rust to use
+ value: ${{ jobs.prepare-pipeline.outputs.RUST_ENV }}
+
+ IMAGE_NAME:
+ description: The name of the image to build
+ value: ${{ jobs.prepare-pipeline.outputs.IMAGE_NAME }}
+
+jobs:
+ prepare-pipeline:
+ runs-on: ubuntu-latest
+
+ outputs:
+ DEPLOY_ENV: ${{ steps.deploy-env.outputs.DEPLOY_ENV }}
+ RUST_ENV: ${{ steps.rust-version.outputs.RUST_VERSION }}
+ IMAGE_NAME: ${{ steps.image-name.outputs.IMAGE_NAME }}
+
+ steps:
+ - name: Set deployment variable
+ id: deploy-env
+ env:
+ BRANCH: ${{ github.ref_name }}
+ run: |
+ if [[ $BRANCH == "main" || $BRANCH == "master" ]]; then
+ DEPLOY_ENV=PROD
+ elif [[ $BRANCH == "staging" ]]; then
+ DEPLOY_ENV=STAGING
+ else
+ DEPLOY_ENV=TEST
+ fi
+
+ echo "DEPLOY_ENV="$DEPLOY_ENV
+ echo "DEPLOY_ENV=$DEPLOY_ENV" >> $GITHUB_OUTPUT
+
+ - name: Set Rust version
+ id: rust-version
+ env:
+ RUST_VERSION: ${{ vars.RUST_VERSION }}
+ run: |
+ if [[ -n "$RUST_VERSION" ]]; then
+ RUST_VERSION=$RUST_VERSION
+ else
+ RUST_VERSION=stable
+ fi
+
+ echo "RUST_VERSION="$RUST_VERSION
+ echo "RUST_VERSION=$RUST_VERSION" >> $GITHUB_OUTPUT
+
+ - name: Set image name
+ id : image-name
+ env:
+ GIT_REPOSITORY: ${{ github.repository }}
+ run: |
+ IMAGE_NAME=$GIT_REPOSITORY
+ echo "IMAGE_NAME="$IMAGE_NAME
+ echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_OUTPUT
+
+ - name: Write prepare summary
+ run: |
+ echo '### Prepare pipeline:
+
+
+ 🎯 Deploy env |
+ ${{ steps.deploy-env.outputs.DEPLOY_ENV }} |
+
+
+ 🦀 Rust version |
+ ${{ steps.rust-version.outputs.RUST_VERSION }} |
+
+
+ 🐳 Image name |
+ ${{ steps.image-name.outputs.IMAGE_NAME }} |
+
+
' >> $GITHUB_STEP_SUMMARY
\ No newline at end of file
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
deleted file mode 100644
index 7588b3e..0000000
--- a/.github/workflows/test.yml
+++ /dev/null
@@ -1,41 +0,0 @@
-name: CI
-
-on:
- push:
- branches:
- - "main"
-
-jobs:
- CI:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v3
-
- - name: Setup enviroment
- run: |
- rustup update
- rustup install nightly
- rustup component add clippy
- rustup target add wasm32-unknown-unknown
- cargo install --locked cargo-leptos
-
- - name: Toolchain info
- run: |
- cargo --version --verbose
- rustc --version
- cargo clippy --version
- cargo leptos --version
-
- - name: Lint
- run: cargo clippy --all-targets --all-features
-
- - name: Test
- run: |
- cargo check
- cargo leptos test
-
- - name: Build package
- run: |
- npm install tailwindcss -g
- npx tailwindcss -i style/tailwind.css -o style/generated.css --minify
- cargo leptos build --release
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index 40a5ad0..45c65a9 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,20 +1,24 @@
+ARG RUST_VERSION
FROM rust:alpine3.18 AS builder
WORKDIR /build
RUN apk update && \
- apk upgrade --no-cache && \
- apk add pkgconfig libressl-dev musl-dev npm
+ apk upgrade && \
+ apk add pkgconfig libressl-dev musl-dev npm --no-cache
-RUN rustup default nightly
-RUN rustup target add wasm32-unknown-unknown
+COPY rust-toolchain.toml .
-RUN cargo install --locked cargo-leptos
-RUN npm install tailwindcss -g
+RUN rustup update && \
+ rustup install ${RUST_VERSION} && \
+ rustup default ${RUST_VERSION} && \
+ rustup target add wasm32-unknown-unknown && \
+ cargo install --locked cargo-leptos && \
+ npm install tailwindcss -g
COPY . .
-RUN npx tailwindcss -i style/tailwind.css -o style/generated.css --minify
-RUN LEPTOS_WASM_OPT_VERSION=version_117 cargo leptos build --release -vv
+RUN npx tailwindcss -i style/tailwind.css -o style/generated.css --minify \
+ LEPTOS_WASM_OPT_VERSION=version_117 cargo leptos build --release -vv
FROM alpine:3.18 AS runner
diff --git a/test.json b/test.json
deleted file mode 100644
index c492c33..0000000
--- a/test.json
+++ /dev/null
@@ -1,113 +0,0 @@
-[
- {
- "id": 596534946,
- "node_id": "R_kgDOI45mog",
- "name": "portfolio-rs",
- "full_name": "Kanerix/portfolio-rs",
- "private": false,
- "owner": {
- "login": "Kanerix",
- "id": 57803719,
- "node_id": "MDQ6VXNlcjU3ODAzNzE5",
- "avatar_url": "https://avatars.githubusercontent.com/u/57803719?v=4",
- "gravatar_id": "",
- "url": "https://api.github.com/users/Kanerix",
- "html_url": "https://github.com/Kanerix",
- "followers_url": "https://api.github.com/users/Kanerix/followers",
- "following_url": "https://api.github.com/users/Kanerix/following{/other_user}",
- "gists_url": "https://api.github.com/users/Kanerix/gists{/gist_id}",
- "starred_url": "https://api.github.com/users/Kanerix/starred{/owner}{/repo}",
- "subscriptions_url": "https://api.github.com/users/Kanerix/subscriptions",
- "organizations_url": "https://api.github.com/users/Kanerix/orgs",
- "repos_url": "https://api.github.com/users/Kanerix/repos",
- "events_url": "https://api.github.com/users/Kanerix/events{/privacy}",
- "received_events_url": "https://api.github.com/users/Kanerix/received_events",
- "type": "User",
- "site_admin": false
- },
- "html_url": "https://github.com/Kanerix/portfolio-rs",
- "description": "My portfolio website, made with Leptos",
- "fork": false,
- "url": "https://api.github.com/repos/Kanerix/portfolio-rs",
- "forks_url": "https://api.github.com/repos/Kanerix/portfolio-rs/forks",
- "keys_url": "https://api.github.com/repos/Kanerix/portfolio-rs/keys{/key_id}",
- "collaborators_url": "https://api.github.com/repos/Kanerix/portfolio-rs/collaborators{/collaborator}",
- "teams_url": "https://api.github.com/repos/Kanerix/portfolio-rs/teams",
- "hooks_url": "https://api.github.com/repos/Kanerix/portfolio-rs/hooks",
- "issue_events_url": "https://api.github.com/repos/Kanerix/portfolio-rs/issues/events{/number}",
- "events_url": "https://api.github.com/repos/Kanerix/portfolio-rs/events",
- "assignees_url": "https://api.github.com/repos/Kanerix/portfolio-rs/assignees{/user}",
- "branches_url": "https://api.github.com/repos/Kanerix/portfolio-rs/branches{/branch}",
- "tags_url": "https://api.github.com/repos/Kanerix/portfolio-rs/tags",
- "blobs_url": "https://api.github.com/repos/Kanerix/portfolio-rs/git/blobs{/sha}",
- "git_tags_url": "https://api.github.com/repos/Kanerix/portfolio-rs/git/tags{/sha}",
- "git_refs_url": "https://api.github.com/repos/Kanerix/portfolio-rs/git/refs{/sha}",
- "trees_url": "https://api.github.com/repos/Kanerix/portfolio-rs/git/trees{/sha}",
- "statuses_url": "https://api.github.com/repos/Kanerix/portfolio-rs/statuses/{sha}",
- "languages_url": "https://api.github.com/repos/Kanerix/portfolio-rs/languages",
- "stargazers_url": "https://api.github.com/repos/Kanerix/portfolio-rs/stargazers",
- "contributors_url": "https://api.github.com/repos/Kanerix/portfolio-rs/contributors",
- "subscribers_url": "https://api.github.com/repos/Kanerix/portfolio-rs/subscribers",
- "subscription_url": "https://api.github.com/repos/Kanerix/portfolio-rs/subscription",
- "commits_url": "https://api.github.com/repos/Kanerix/portfolio-rs/commits{/sha}",
- "git_commits_url": "https://api.github.com/repos/Kanerix/portfolio-rs/git/commits{/sha}",
- "comments_url": "https://api.github.com/repos/Kanerix/portfolio-rs/comments{/number}",
- "issue_comment_url": "https://api.github.com/repos/Kanerix/portfolio-rs/issues/comments{/number}",
- "contents_url": "https://api.github.com/repos/Kanerix/portfolio-rs/contents/{+path}",
- "compare_url": "https://api.github.com/repos/Kanerix/portfolio-rs/compare/{base}...{head}",
- "merges_url": "https://api.github.com/repos/Kanerix/portfolio-rs/merges",
- "archive_url": "https://api.github.com/repos/Kanerix/portfolio-rs/{archive_format}{/ref}",
- "downloads_url": "https://api.github.com/repos/Kanerix/portfolio-rs/downloads",
- "issues_url": "https://api.github.com/repos/Kanerix/portfolio-rs/issues{/number}",
- "pulls_url": "https://api.github.com/repos/Kanerix/portfolio-rs/pulls{/number}",
- "milestones_url": "https://api.github.com/repos/Kanerix/portfolio-rs/milestones{/number}",
- "notifications_url": "https://api.github.com/repos/Kanerix/portfolio-rs/notifications{?since,all,participating}",
- "labels_url": "https://api.github.com/repos/Kanerix/portfolio-rs/labels{/name}",
- "releases_url": "https://api.github.com/repos/Kanerix/portfolio-rs/releases{/id}",
- "deployments_url": "https://api.github.com/repos/Kanerix/portfolio-rs/deployments",
- "created_at": "2023-02-02T11:56:32Z",
- "updated_at": "2023-12-30T19:28:11Z",
- "pushed_at": "2024-01-02T19:28:03Z",
- "git_url": "git://github.com/Kanerix/portfolio-rs.git",
- "ssh_url": "git@github.com:Kanerix/portfolio-rs.git",
- "clone_url": "https://github.com/Kanerix/portfolio-rs.git",
- "svn_url": "https://github.com/Kanerix/portfolio-rs",
- "homepage": "https://portfolio.artilun.com",
- "size": 933,
- "stargazers_count": 5,
- "watchers_count": 5,
- "language": "Rust",
- "has_issues": true,
- "has_projects": true,
- "has_downloads": true,
- "has_wiki": true,
- "has_pages": false,
- "has_discussions": false,
- "forks_count": 0,
- "mirror_url": null,
- "archived": false,
- "disabled": false,
- "open_issues_count": 0,
- "license": {
- "key": "apache-2.0",
- "name": "Apache License 2.0",
- "spdx_id": "Apache-2.0",
- "url": "https://api.github.com/licenses/apache-2.0",
- "node_id": "MDc6TGljZW5zZTI="
- },
- "allow_forking": true,
- "is_template": false,
- "web_commit_signoff_required": false,
- "topics": [
- "flyio",
- "portfolio",
- "rust",
- "tailwindcss"
- ],
- "visibility": "public",
- "forks": 0,
- "open_issues": 0,
- "watchers": 5,
- "default_branch": "main"
- }
-]
\ No newline at end of file