Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanerix committed Mar 11, 2024
2 parents 626ea84 + 8dc96c2 commit c22cdaa
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 175 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 13 additions & 13 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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 }}
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
DOCKER_IMAGE: ${{ github.event.inputs.DOCKER_IMAGE }}
37 changes: 37 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -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 --
38 changes: 38 additions & 0 deletions .github/workflows/pipline.yml
Original file line number Diff line number Diff line change
@@ -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 }}
83 changes: 83 additions & 0 deletions .github/workflows/prepare.yml
Original file line number Diff line number Diff line change
@@ -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:
<table>
<tr>
<td>🎯 Deploy env</td>
<td>${{ steps.deploy-env.outputs.DEPLOY_ENV }}</td>
</tr>
<tr>
<td>🦀 Rust version</td>
<td>${{ steps.rust-version.outputs.RUST_VERSION }}</td>
</tr>
<tr>
<td>🐳 Image name</td>
<td>${{ steps.image-name.outputs.IMAGE_NAME }}</td>
</tr>
</table>' >> $GITHUB_STEP_SUMMARY
41 changes: 0 additions & 41 deletions .github/workflows/test.yml

This file was deleted.

20 changes: 12 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit c22cdaa

Please sign in to comment.