Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init cmmand #1447

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -437,6 +437,7 @@ jobs:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/tc-server
APP_VERSION: ${{ needs.draft_release.outputs.create_release_name }} # Ensure APP_VERSION is set correctly
needs: [draft_release, release]
if: (startsWith(github.event.head_commit.message, 'feat') || startsWith(github.event.head_commit.message, 'fix')) && (github.event_name == 'push' && github.ref == 'refs/heads/main')
runs-on: ubuntu-latest
@@ -461,6 +462,9 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ env.APP_VERSION }}
type=raw,value=latest,enable=${{ endsWith(env.APP_VERSION, '-SNAPSHOT') == false }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
40 changes: 4 additions & 36 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,4 @@
# Builder stage
FROM rust:slim-buster AS builder

WORKDIR /prod
# Copy manifests and the graphql file
COPY Cargo.lock Cargo.toml examples/jsonplaceholder.graphql docker.sh ./

ADD https://github.com/sclevine/yj/releases/download/v5.1.0/yj-linux-amd64 /usr/local/bin/yj
ADD https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_amd64 /usr/local/bin/yq
RUN chmod +x /usr/local/bin/yj /usr/local/bin/yq
RUN chmod +x docker.sh && ./docker.sh

# This is the trick to speed up the building process.
RUN mkdir .cargo \
&& cargo vendor > .cargo/config

# Install required system dependencies and cleanup in the same layer
RUN apt-get update && apt-get install -y pkg-config libssl-dev python g++ git make libglib2.0-dev && apt-get clean && rm -rf /var/lib/apt/lists/*

# Copy the rest of the source code
COPY . .

RUN chmod +x docker.sh && ./docker.sh

# Compile the project
RUN RUST_BACKTRACE=1 cargo build --release

# Runner stage
FROM fedora:41 AS runner

# Copy necessary files from the builder stage
COPY --from=builder /prod/target/release/tailcall /bin
COPY --from=builder /prod/jsonplaceholder.graphql /jsonplaceholder.graphql

ENV TAILCALL_LOG_LEVEL=error
CMD ["/bin/tailcall", "start", "jsonplaceholder.graphql"]
FROM ubuntu:latest
RUN apt-get update && apt-get install -y curl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to ubuntu:latest as the base image might introduce unpredictability over time as latest will always point to the newest version. Consider using a more specific version tag (e.g., ubuntu:20.04) to ensure reproducibility and stability of your Docker builds.

RUN curl -sSL https://raw.githubusercontent.com/tailcallhq/tailcall/master/install.sh | bash -s -- v0.55.0
ENV PATH="${PATH}:~/.tailcall/bin"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing a script directly from a URL with curl | bash can be risky, especially without verifying the script's integrity. It's recommended to first download the script, inspect it, and then execute it. Alternatively, consider verifying the script's integrity using a checksum or a GPG signature if available.

5 changes: 5 additions & 0 deletions src/cli/tc.rs
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ use crate::print_schema;

const FILE_NAME: &str = ".tailcallrc.graphql";
const YML_FILE_NAME: &str = ".graphqlrc.yml";
const JSON_FILE_NAME: &str = ".tailcallrc.schema.json";

pub async fn run() -> Result<()> {
let cli = Cli::parse();
@@ -73,8 +74,10 @@ pub async fn init(folder_path: &str) -> Result<()> {
}

let tailcallrc = include_str!("../../generated/.tailcallrc.graphql");
let tailcallrc_json: &str = include_str!("../../generated/.tailcallrc.schema.json");

let file_path = Path::new(folder_path).join(FILE_NAME);
let json_file_path = Path::new(folder_path).join(JSON_FILE_NAME);
let yml_file_path = Path::new(folder_path).join(YML_FILE_NAME);

let tailcall_exists = fs::metadata(&file_path).is_ok();
@@ -87,9 +90,11 @@ pub async fn init(folder_path: &str) -> Result<()> {

if confirm {
fs::write(&file_path, tailcallrc.as_bytes())?;
fs::write(&json_file_path, tailcallrc_json.as_bytes())?;
}
} else {
fs::write(&file_path, tailcallrc.as_bytes())?;
fs::write(&json_file_path, tailcallrc_json.as_bytes())?;
}

let yml_exists = fs::metadata(&yml_file_path).is_ok();