I am building my own app deployment platform where users can create a project by connecting to Github and then they can choose which repo they want to build and host using my platform. You can compare it with Vercel or Railway.
I want to use AWS under the hood to manage deployments and hosting.
So I read the docs for AWS CodeBuild SDK
And I thought that was exactly what I needed to build the projects of my customers.
But I came to a problem.
I don’t think you can create a CodeBuild project using github personal access tokens.
You can only do it by connecting your account via oauth in amazon console.
This is the code that I tried:
export async function buildProject(projectName: string, mainBranch: string) {
const session = await auth();
if (!session) {
return;
}
try {
const githubAccessToken = session.user?.accessToken;
console.log(`https://${githubAccessToken}@github.com/${projectName}`);
const codebuild = new CodeBuildClient({
region: "us-west-1",
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
},
});
const params: CreateProjectInput = {
// Create a unique project name
serviceRole: "arn:aws:iam::051950967555:role/codebuild-dev",
name: uuidv4(),
sourceVersion: mainBranch,
source: {
type: "GITHUB",
location: `https://github.com/${projectName}`,
auth: {
type: "PERSONAL_ACCESS_TOKEN", // Type '"PERSONAL_ACCESS_TOKEN"' is not assignable to type 'SourceAuthType | undefined'.
resource: githubAccessToken,
},
},
artifacts: {
type: "NO_ARTIFACTS",
},
environment: {
computeType: "BUILD_GENERAL1_SMALL",
type: "LINUX_CONTAINER",
image: "aws/codebuild/standard:4.0",
},
};
const project = await codebuild.send(new CreateProjectCommand(params));
return project;
} catch (error) {
console.log(error);
return false;
}
}
So now I am wondering if i am even using the right service for this.
Should I use codebuild if I want to reploy apps for hundreds of user? or should I use codepipeline?
My original idea whas to do it via codebuild, install buildpacks and use it to generate a docker image and then host it on ECS
Thanks you in advance
I tried using using codebuild because I thought it was a good option for building all user repos, but maybe I need to use codepipeline or even provision my own EC2 instances? for building the source code
Ray Orolé is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.