From 5ee221a77a7417707ae7385226a79b1a7ce29a24 Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Wed, 6 Mar 2024 10:10:03 +0100 Subject: [PATCH 01/12] Removed file that was added by accident --- test.json | 113 ------------------------------------------------------ 1 file changed, 113 deletions(-) delete mode 100644 test.json 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 From e6fffac17ebaa8b523cf1ee347aceb103adb7adb Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Wed, 6 Mar 2024 12:25:23 +0100 Subject: [PATCH 02/12] Created workflows --- .github/workflows/build.yml | 46 ++++++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 12 +++------ .github/workflows/linter.yml | 25 +++++++++++++++++ .github/workflows/pipline.yml | 28 +++++++++++++++++++ .github/workflows/setup-rust.yml | 30 +++++++++++++++++++++ .github/workflows/test.yml | 40 +++++---------------------- 6 files changed, 138 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/linter.yml create mode 100644 .github/workflows/pipline.yml create mode 100644 .github/workflows/setup-rust.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..ffe29c7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,46 @@ +name: Build and push docker image + +on: + workflow_call: + inputs: + RUST_VERSION: + description: The Rust version to use + 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: + runs-on: ubuntu-latest + + outputs: + DOCKER_IMAGE: ${{ steps.docker-meta.outputs.tags }} + + # Permissions granted to `GITHUB_TOKEN` for actions in this job. + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - 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 \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b600731..f3b14d6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,16 +1,10 @@ -name: CD +name: Deploy app on: - workflow_run: - workflows: - - CI - branches: - - main - types: - - completed + workflow_call: jobs: - CD: + deploy: name: Deploy app runs-on: ubuntu-latest steps: diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..ad719c7 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,25 @@ +name: Linter + +on: + workflow_call: + inputs: + DOCKER_IMAGE: + description: Docker image to use for the workflow + type: string + +jobs: + linter: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Lint Dockerfile + run: | + docker run --rm -i hadolint/hadolint < Dockerfile + + - name: Lint Rust project + uses: .github/workflows/setup-rust.yml + with: + RUST_VERSION: ${{ vars.RUST_VERSION }} \ No newline at end of file diff --git a/.github/workflows/pipline.yml b/.github/workflows/pipline.yml new file mode 100644 index 0000000..76bc0ff --- /dev/null +++ b/.github/workflows/pipline.yml @@ -0,0 +1,28 @@ +name: Pipeline + +on: + push: + branches: + - 'main' + paths-ignore: + - 'LICENSE' + - 'README.md' + - 'CHANGELOG.md' + +jobs: + linter: + uses: .github/workflows/linter.yml + secrets: inherit + + build: + uses: .github/workflows/build.yml + secrets: inherit + + test: + uses: .github/workflows/test.yml + secrets: inherit + + deploy: + needs: [test, linter, build] + uses: .github/workflows/deploy.yml + secrets: inherit diff --git a/.github/workflows/setup-rust.yml b/.github/workflows/setup-rust.yml new file mode 100644 index 0000000..ac48203 --- /dev/null +++ b/.github/workflows/setup-rust.yml @@ -0,0 +1,30 @@ +name: setup-rust + +on: + workflow_call: + inputs: + RUST_VERSION: + description: The version of rust to use + default: nightly + type: string + +jobs: + setup-rust: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup environment + run: | + rustup update + rustup install ${{ inputs.RUST_VERSION }} + 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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7588b3e..afffe73 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,41 +1,13 @@ -name: CI +name: Test on: - push: - branches: - - "main" + workflow_call: jobs: - CI: + test: 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 + steps: + - name: Get Docker image 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 + echo "Hello, world!" \ No newline at end of file From aea01dd650b2a83a6626b3009bf0841de92cc118 Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Wed, 6 Mar 2024 22:41:31 +0100 Subject: [PATCH 03/12] More work on actions --- .github/workflows/build.yml | 31 +++++++++++- .github/workflows/deploy.yml | 12 +++-- .github/workflows/linter.yml | 14 ++++-- .github/workflows/pipline.yml | 26 +++++++--- .github/workflows/prepare.yml | 83 ++++++++++++++++++++++++++++++++ .github/workflows/setup-rust.yml | 15 ++++-- .github/workflows/test.yml | 13 ----- Dockerfile | 3 +- 8 files changed, 164 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/prepare.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ffe29c7..7b36112 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,10 +3,21 @@ 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 @@ -18,6 +29,7 @@ env: jobs: build-and-push-image: + if: inputs.DEPLOY_ENV == 'production' runs-on: ubuntu-latest outputs: @@ -32,7 +44,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Log in to the Container registry + - 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 }} @@ -43,4 +58,16 @@ jobs: id: docker-meta uses: docker/metadata-action@v3 with: - images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}:latest \ No newline at end of file + 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 f3b14d6..c320994 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,6 +2,11 @@ name: Deploy app on: workflow_call: + inputs: + DOCKER_IMAGE: + description: 'Path to the image' + required: true + type: string jobs: deploy: @@ -10,7 +15,8 @@ jobs: 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 index ad719c7..45b4a0a 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -3,6 +3,10 @@ name: Linter on: workflow_call: inputs: + RUST_VERSION: + description: Rust version to use for the workflow + type: string + DOCKER_IMAGE: description: Docker image to use for the workflow type: string @@ -19,7 +23,11 @@ jobs: run: | docker run --rm -i hadolint/hadolint < Dockerfile - - name: Lint Rust project - uses: .github/workflows/setup-rust.yml + - name: Setup rust environment + uses: ./.github/workflows/setup-rust.yml with: - RUST_VERSION: ${{ vars.RUST_VERSION }} \ No newline at end of file + RUST_VERSION: ${{ inputs.RUST_VERSION }} + + - name: Lint Rust code wiht Clippy + run: | + cargo clippy --all-targets --all-features -- -D warnings \ No newline at end of file diff --git a/.github/workflows/pipline.yml b/.github/workflows/pipline.yml index 76bc0ff..fa0d575 100644 --- a/.github/workflows/pipline.yml +++ b/.github/workflows/pipline.yml @@ -10,19 +10,29 @@ on: - 'CHANGELOG.md' jobs: + prepare: + uses: ./.github/workflows/prepare.yml + secrets: inherit + linter: - uses: .github/workflows/linter.yml + uses: ./.github/workflows/linter.yml + needs: [prepare] secrets: inherit + with: + RUST_VERSION: ${{ needs.prepare.outputs.RUST_VERSION }} build: - uses: .github/workflows/build.yml - secrets: inherit - - test: - uses: .github/workflows/test.yml + 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: [test, linter, build] - uses: .github/workflows/deploy.yml + 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..f12841f --- /dev/null +++ b/.github/workflows/prepare.yml @@ -0,0 +1,83 @@ +name: Prepare workflow + +on: + workflow_call: + outputs: + DEPLOY_ENV: + description: What kind of deployment this is + value: ${{ jobs.prepare.outputs.DEPLOY_ENV }} + + RUST_VERSION: + description: The version of Rust to use + value: ${{ jobs.prepare.outputs.RUST_ENV }} + + IMAGE_NAME: + description: The name of the image to build + value: ${{ jobs.prepare.outputs.IMAGE_NAME }} + +jobs: + prepare: + 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 + 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 [[ -f .rust-toolchain.toml ]]; then + RUST_VERSION=$(cat .rust-toolchain.toml) + elif [[ -n "$RUST_VERSION" ]]; then + RUST_VERSION=$RUST_VERSION + else + RUST_VERSION=stable + fi + + echo "RUST_VERSION="$RUST_VERSION + echo "RUST_VERSION=$RUST_VERSIN" >> $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:\n + + + + + + + + + + + + + +
🎯 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/setup-rust.yml b/.github/workflows/setup-rust.yml index ac48203..1dfb78f 100644 --- a/.github/workflows/setup-rust.yml +++ b/.github/workflows/setup-rust.yml @@ -7,6 +7,11 @@ on: description: The version of rust to use default: nightly type: string + + wasm: + description: Whether to add wasm + default: false + type: boolean jobs: setup-rust: @@ -15,15 +20,19 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Setup environment + - 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 + if: ${{ inputs.wasm }} + run: | rustup target add wasm32-unknown-unknown - cargo install --locked cargo-leptos - - name: Toolchain info + - name: Write toolchain info run: | cargo --version --verbose rustc --version diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index afffe73..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Test - -on: - workflow_call: - -jobs: - test: - runs-on: ubuntu-latest - - steps: - - name: Get Docker image - run: | - echo "Hello, world!" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 40a5ad0..6054ca3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM rust:alpine3.18 AS builder +ARG RUST_VERSION +FROM rust:${RUST_VERSION}-alpine3.18 AS builder WORKDIR /build RUN apk update && \ From ca6f53b36203f01f52f9021d299743b615f38479 Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:13:05 +0100 Subject: [PATCH 04/12] Fixed mistake in actions --- .github/workflows/pipline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pipline.yml b/.github/workflows/pipline.yml index fa0d575..159f9bb 100644 --- a/.github/workflows/pipline.yml +++ b/.github/workflows/pipline.yml @@ -3,7 +3,7 @@ name: Pipeline on: push: branches: - - 'main' + - '**' paths-ignore: - 'LICENSE' - 'README.md' From f05a609d531d3ab6b002787245d910b2a750154e Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:27:44 +0100 Subject: [PATCH 05/12] More workflow changes --- .github/workflows/build.yml | 5 ----- .github/workflows/deploy.yml | 3 ++- .github/workflows/prepare.yml | 8 ++++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7b36112..63d389d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,11 +35,6 @@ jobs: outputs: DOCKER_IMAGE: ${{ steps.docker-meta.outputs.tags }} - # Permissions granted to `GITHUB_TOKEN` for actions in this job. - permissions: - contents: read - packages: write - steps: - name: Checkout repository uses: actions/checkout@v2 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c320994..128922f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,4 +19,5 @@ jobs: flyctl deploy --remote-only --image ${{ env.DOCKER_IMAGE }} env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - DOCKER_IMAGE: ${{ github.event.inputs.DOCKER_IMAGE }} \ No newline at end of file + DOCKER_IMAGE: ${{ github.event.inputs.DOCKER_IMAGE }} + name: deploy-app \ No newline at end of file diff --git a/.github/workflows/prepare.yml b/.github/workflows/prepare.yml index f12841f..e0c8edb 100644 --- a/.github/workflows/prepare.yml +++ b/.github/workflows/prepare.yml @@ -5,18 +5,18 @@ on: outputs: DEPLOY_ENV: description: What kind of deployment this is - value: ${{ jobs.prepare.outputs.DEPLOY_ENV }} + value: ${{ jobs.prepare-pipeline.outputs.DEPLOY_ENV }} RUST_VERSION: description: The version of Rust to use - value: ${{ jobs.prepare.outputs.RUST_ENV }} + value: ${{ jobs.prepare-pipeline.outputs.RUST_ENV }} IMAGE_NAME: description: The name of the image to build - value: ${{ jobs.prepare.outputs.IMAGE_NAME }} + value: ${{ jobs.prepare-pipeline.outputs.IMAGE_NAME }} jobs: - prepare: + prepare-pipeline: runs-on: ubuntu-latest outputs: From 72aa4e7cd38846b162e14d5e27d108ed5034b37e Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:31:39 +0100 Subject: [PATCH 06/12] Workflow fixes --- .github/workflows/deploy.yml | 7 +++---- .github/workflows/linter.yml | 4 ++-- .github/workflows/pipline.yml | 2 +- .github/workflows/prepare.yml | 4 +++- .github/workflows/setup-rust.yml | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 128922f..b7977dc 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,9 +9,9 @@ on: type: string jobs: - deploy: - name: Deploy app + deploy-app: runs-on: ubuntu-latest + steps: - uses: actions/checkout@v3 - uses: superfly/flyctl-actions/setup-flyctl@master @@ -19,5 +19,4 @@ jobs: flyctl deploy --remote-only --image ${{ env.DOCKER_IMAGE }} env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - DOCKER_IMAGE: ${{ github.event.inputs.DOCKER_IMAGE }} - name: deploy-app \ No newline at end of file + 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 index 45b4a0a..daf5853 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,4 +1,4 @@ -name: Linter +name: Lint project on: workflow_call: @@ -12,7 +12,7 @@ on: type: string jobs: - linter: + lint-project: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/pipline.yml b/.github/workflows/pipline.yml index 159f9bb..5d77599 100644 --- a/.github/workflows/pipline.yml +++ b/.github/workflows/pipline.yml @@ -1,4 +1,4 @@ -name: Pipeline +name: Project ipeline on: push: diff --git a/.github/workflows/prepare.yml b/.github/workflows/prepare.yml index e0c8edb..65f86a4 100644 --- a/.github/workflows/prepare.yml +++ b/.github/workflows/prepare.yml @@ -1,4 +1,4 @@ -name: Prepare workflow +name: Prepare pipeline on: workflow_call: @@ -32,6 +32,8 @@ jobs: run: | if [[ $BRANCH == "main" || $BRANCH == "master" ]]; then DEPLOY_ENV=PROD + elif [[ $BRANCH == "staging" ]]; then + DEPLOY_ENV=STAGING else DEPLOY_ENV=TEST fi diff --git a/.github/workflows/setup-rust.yml b/.github/workflows/setup-rust.yml index 1dfb78f..4d10750 100644 --- a/.github/workflows/setup-rust.yml +++ b/.github/workflows/setup-rust.yml @@ -1,4 +1,4 @@ -name: setup-rust +name: Setup rust on: workflow_call: From e9bad8414446f33843b91bb750cc4c21471e591b Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:49:09 +0100 Subject: [PATCH 07/12] Fixed some docker stuff and workflow --- .github/workflows/linter.yml | 2 +- .github/workflows/prepare.yml | 4 +--- Dockerfile | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index daf5853..6441565 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Lint Dockerfile run: | diff --git a/.github/workflows/prepare.yml b/.github/workflows/prepare.yml index 65f86a4..21212c7 100644 --- a/.github/workflows/prepare.yml +++ b/.github/workflows/prepare.yml @@ -46,9 +46,7 @@ jobs: env: RUST_VERSION: ${{ vars.RUST_VERSION }} run: | - if [[ -f .rust-toolchain.toml ]]; then - RUST_VERSION=$(cat .rust-toolchain.toml) - elif [[ -n "$RUST_VERSION" ]]; then + if [[ -n "$RUST_VERSION" ]]; then RUST_VERSION=$RUST_VERSION else RUST_VERSION=stable diff --git a/Dockerfile b/Dockerfile index 6054ca3..161474e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,19 +3,21 @@ FROM rust:${RUST_VERSION}-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 \ + rm -r /var/cache/apk/* -RUN rustup default nightly -RUN rustup target add wasm32-unknown-unknown - -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@3.4 -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 From 98bfe6b45c5b478aa3885879b39a5360b2c6b533 Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Thu, 7 Mar 2024 21:20:45 +0100 Subject: [PATCH 08/12] Removed docker linting --- .github/workflows/linter.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 6441565..0c854a0 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -7,10 +7,6 @@ on: description: Rust version to use for the workflow type: string - DOCKER_IMAGE: - description: Docker image to use for the workflow - type: string - jobs: lint-project: runs-on: ubuntu-latest @@ -19,10 +15,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Lint Dockerfile - run: | - docker run --rm -i hadolint/hadolint < Dockerfile - - name: Setup rust environment uses: ./.github/workflows/setup-rust.yml with: From 7d9b921459c4a391b7135abf1e013d3e80a08b6d Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Thu, 7 Mar 2024 21:23:42 +0100 Subject: [PATCH 09/12] Fixed setup-rust workflow --- .github/workflows/setup-rust.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/setup-rust.yml b/.github/workflows/setup-rust.yml index 4d10750..0a8e06a 100644 --- a/.github/workflows/setup-rust.yml +++ b/.github/workflows/setup-rust.yml @@ -9,7 +9,7 @@ on: type: string wasm: - description: Whether to add wasm + description: Whether to add wasm target default: false type: boolean @@ -18,8 +18,6 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Setup Rust environment run: | rustup update From 8610526edfa7a59c3f63f9af5c48e9a3e4d18f65 Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Thu, 7 Mar 2024 21:33:04 +0100 Subject: [PATCH 10/12] Fixed linting workflow --- .github/workflows/linter.yml | 22 ++++++++++++++----- .github/workflows/setup-rust.yml | 37 -------------------------------- 2 files changed, 17 insertions(+), 42 deletions(-) delete mode 100644 .github/workflows/setup-rust.yml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 0c854a0..2508fdd 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -15,11 +15,23 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Setup rust environment - uses: ./.github/workflows/setup-rust.yml - with: - RUST_VERSION: ${{ inputs.RUST_VERSION }} - + - 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 -- -D warnings \ No newline at end of file diff --git a/.github/workflows/setup-rust.yml b/.github/workflows/setup-rust.yml deleted file mode 100644 index 0a8e06a..0000000 --- a/.github/workflows/setup-rust.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Setup rust - -on: - workflow_call: - inputs: - RUST_VERSION: - description: The version of rust to use - default: nightly - type: string - - wasm: - description: Whether to add wasm target - default: false - type: boolean - -jobs: - setup-rust: - runs-on: ubuntu-latest - - steps: - - 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 - if: ${{ inputs.wasm }} - run: | - rustup target add wasm32-unknown-unknown - - - name: Write toolchain info - run: | - cargo --version --verbose - rustc --version - cargo clippy --version From 83061c1e82cf101ab5f198eee977ab924fbaf009 Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Thu, 7 Mar 2024 21:57:11 +0100 Subject: [PATCH 11/12] Played around with docker --- .github/workflows/prepare.yml | 4 ++-- Dockerfile | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/prepare.yml b/.github/workflows/prepare.yml index 21212c7..f396477 100644 --- a/.github/workflows/prepare.yml +++ b/.github/workflows/prepare.yml @@ -53,7 +53,7 @@ jobs: fi echo "RUST_VERSION="$RUST_VERSION - echo "RUST_VERSION=$RUST_VERSIN" >> $GITHUB_OUTPUT + echo "RUST_VERSION=$RUST_VERSION" >> $GITHUB_OUTPUT - name: Set image name id : image-name @@ -66,7 +66,7 @@ jobs: - name: Write prepare summary run: | - echo '### Prepare pipeline:\n + echo '### Prepare pipeline: diff --git a/Dockerfile b/Dockerfile index 161474e..45c65a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,19 @@ ARG RUST_VERSION -FROM rust:${RUST_VERSION}-alpine3.18 AS builder +FROM rust:alpine3.18 AS builder WORKDIR /build RUN apk update && \ apk upgrade && \ - apk add pkgconfig libressl-dev musl-dev npm --no-cache \ - rm -r /var/cache/apk/* - -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@3.4 -g + apk add pkgconfig libressl-dev musl-dev npm --no-cache + +COPY rust-toolchain.toml . + +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 . . From 8dc96c27ecead1b278ac3d53051ee5c58f9a9bef Mon Sep 17 00:00:00 2001 From: Kasper <57803719+Kanerix@users.noreply.github.com> Date: Thu, 7 Mar 2024 21:59:59 +0100 Subject: [PATCH 12/12] Removed warnings as error from linter --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 2508fdd..edda6f0 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -34,4 +34,4 @@ jobs: - name: Lint Rust code wiht Clippy run: | - cargo clippy --all-targets --all-features -- -D warnings \ No newline at end of file + cargo clippy --all-targets --all-features -- \ No newline at end of file
🎯 Deploy env