Skip to content

Commit af67196

Browse files
committed
deploy on push
1 parent 85a789f commit af67196

5 files changed

Lines changed: 141 additions & 28 deletions

File tree

β€Ž.ebextensions/02_run_migrations.configβ€Ž

Lines changed: 0 additions & 19 deletions
This file was deleted.

β€Ž.ebextensions/03_install_psql.configβ€Ž

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Deploy to Production
2+
3+
on:
4+
push:
5+
branches:
6+
- infrastructure
7+
- multitenancy
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 30
13+
14+
steps:
15+
- name: Checkout source code
16+
uses: actions/checkout@v3
17+
18+
- name: Configure AWS credentials
19+
uses: aws-actions/configure-aws-credentials@v1
20+
with:
21+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
22+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23+
aws-region: us-east-1
24+
25+
- name: Login to Amazon ECR
26+
id: login-ecr
27+
uses: aws-actions/amazon-ecr-login@v1
28+
29+
- name: Set up Docker Buildx (for multi-platform builds)
30+
uses: docker/setup-buildx-action@v2
31+
32+
- name: Build, tag, and push image to Amazon ECR
33+
env:
34+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
35+
ECR_REPOSITORY: finishline-production
36+
IMAGE_TAG: ${{ github.sha }}
37+
run: |
38+
echo "Building Docker image for AMD64 architecture..."
39+
40+
# Build for AMD64 architecture (t3.small instances are AMD64)
41+
docker buildx build \
42+
--platform linux/amd64 \
43+
--tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
44+
--tag $ECR_REGISTRY/$ECR_REPOSITORY:latest \
45+
--push \
46+
.
47+
48+
echo "βœ… Image pushed successfully"
49+
echo "Image: $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
50+
51+
- name: Update Dockerrun.aws.json
52+
env:
53+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
54+
ECR_REPOSITORY: finishline-production
55+
IMAGE_TAG: ${{ github.sha }}
56+
run: |
57+
# Create a deployment-specific Dockerrun.aws.json with the commit SHA
58+
cat > Dockerrun.aws.json <<EOF
59+
{
60+
"AWSEBDockerrunVersion": "1",
61+
"Image": {
62+
"Name": "$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG",
63+
"Update": "true"
64+
},
65+
"Ports": [
66+
{
67+
"ContainerPort": 3001,
68+
"HostPort": 3001
69+
}
70+
]
71+
}
72+
EOF
73+
74+
echo "βœ… Dockerrun.aws.json updated with image tag: $IMAGE_TAG"
75+
76+
- name: Create deployment package
77+
run: |
78+
# Include .ebextensions for health check configuration
79+
zip -r deploy.zip Dockerrun.aws.json .ebextensions/ .ebignore
80+
81+
echo "βœ… Deployment package created"
82+
83+
- name: Deploy to Elastic Beanstalk
84+
uses: einaregilsson/beanstalk-deploy@v21
85+
with:
86+
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
87+
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
88+
application_name: finishline-production
89+
environment_name: finishline-production-env
90+
version_label: ${{ github.sha }}
91+
region: us-east-1
92+
deployment_package: deploy.zip
93+
wait_for_deployment: true
94+
wait_for_environment_recovery: 300
95+
96+
- name: Verify deployment
97+
run: |
98+
echo "πŸŽ‰ Deployment completed successfully!"
99+
echo ""
100+
echo "Deployment Details:"
101+
echo " Image: ${{ steps.login-ecr.outputs.registry }}/finishline-production:${{ github.sha }}"
102+
echo " Version: ${{ github.sha }}"
103+
echo " Environment: finishline-production-env"

β€ŽDockerfileβ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ WORKDIR /app
1818
RUN apt-get update -y && apt-get install -y openssl && rm -rf /var/lib/apt/lists/*
1919

2020
COPY package.json ./
21-
# COPY .yarn ./.yarn
2221

2322
COPY src/backend/package.json ./src/backend/
2423
COPY src/shared/package.json ./src/shared/
@@ -34,6 +33,12 @@ COPY --from=builder /app/src/backend/src/prisma ./src/backend/src/prisma
3433
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
3534
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
3635

36+
# Copy the entrypoint script to run migrations
37+
COPY docker-entrypoint.sh /docker-entrypoint.sh
38+
RUN chmod +x /docker-entrypoint.sh
39+
3740
EXPOSE 3001
3841

42+
# Use entrypoint to run migrations before starting app
43+
ENTRYPOINT ["/docker-entrypoint.sh"]
3944
CMD ["yarn", "backend"]

β€Ždocker-entrypoint.shβ€Ž

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "πŸš€ Starting FinishLine backend..."
5+
6+
# Check if DATABASE_URL is set
7+
if [ -z "$DATABASE_URL" ]; then
8+
echo "❌ ERROR: DATABASE_URL environment variable is not set"
9+
exit 1
10+
fi
11+
12+
echo "πŸ“Š Database URL is configured"
13+
14+
# Run migrations
15+
echo "πŸ”„ Running Prisma migrations..."
16+
cd /app/src/backend
17+
18+
# Run migrations with proper error handling
19+
if npx prisma migrate deploy; then
20+
echo "βœ… Migrations completed successfully"
21+
else
22+
echo "❌ ERROR: Migrations failed"
23+
exit 1
24+
fi
25+
26+
# Return to app directory
27+
cd /app
28+
29+
echo "πŸŽ‰ Migrations complete, starting application..."
30+
31+
# Execute the CMD passed to docker run
32+
exec "$@"

0 commit comments

Comments
Β (0)