Sau khi test thành công, bạn sẽ push code lên GitLab để version control và chuẩn bị cho CI/CD.
1. Check Git Status
# Navigate to project root
cd /path/to/everyonecook-dev
# Check if Git is already initialized
git status
# If not initialized:
git init
2. Configure Git
# Set your name and email
git config user.name "Your Name"
git config user.email "your.email@example.com"
# Verify configuration
git config --list
1. Create .gitignore File
# Create .gitignore
cat > .gitignore << 'EOF'
# Dependencies
node_modules/
package-lock.json
yarn.lock
# Build outputs
dist/
build/
*.js.map
*.d.ts.map
cdk.out/
.next/
# Environment variables
.env
.env.local
.env.*.local
# AWS
*.pem
*.key
cloudfront-private-key.pem
# Deployment packages
*.zip
deployment/
# Logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# OS
.DS_Store
Thumbs.db
# Test coverage
coverage/
.nyc_output/
# Temporary files
tmp/
temp/
*.tmp
# CDK
cdk.context.json
outputs.json
# TypeScript
*.tsbuildinfo
EOF
Screenshot: .gitignore file content
1. Add Files to Staging
# Add all files
git add .
# Check what will be committed
git status
2. Create Initial Commit
# Commit with message
git commit -m "Initial commit: EveryoneCook infrastructure and backend"
# Verify commit
git log --oneline
Screenshot: Terminal showing initial commit
1. Login to GitLab
Go to https://gitlab.com/ and login
2. Create New Project
everyonecook
Screenshot: GitLab showing new project created
3. Get Repository URL
# HTTPS URL
https://gitlab.com/your-username/everyonecook.git
# SSH URL (if you have SSH key configured)
git@gitlab.com:your-username/everyonecook.git
1. Add GitLab Remote
# Add remote (use HTTPS)
git remote add origin https://gitlab.com/your-username/everyonecook.git
# Or use SSH
git remote add origin git@gitlab.com:your-username/everyonecook.git
# Verify remote
git remote -v
2. Push to GitLab
# Push to main branch
git push -u origin main
# Enter GitLab credentials if using HTTPS
# Username: your-username
# Password: your-personal-access-token (not your password!)
Screenshot: Terminal showing successful push to GitLab
3. Verify on GitLab
Go to your GitLab repository and verify files are uploaded.
Screenshot: GitLab showing repository with files
1. Create Development Branch
# Create and switch to dev branch
git checkout -b dev
# Push dev branch
git push -u origin dev
2. Create Feature Branch
# Create feature branch from dev
git checkout -b feature/add-notifications
# Make changes...
# Commit changes...
# Push feature branch
git push -u origin feature/add-notifications
3. Branch Strategy
main (production)
↓
dev (development)
↓
feature/* (features)
hotfix/* (urgent fixes)
1. Create .gitlab-ci.yml
# Create CI/CD configuration
cat > .gitlab-ci.yml << 'EOF'
image: node:20
stages:
- test
- build
- deploy
variables:
AWS_DEFAULT_REGION: us-east-1
# Cache node_modules
cache:
paths:
- node_modules/
- infrastructure/node_modules/
- services/*/node_modules/
# Test stage
test:
stage: test
script:
- npm install
- npm run lint
- npm run test
only:
- merge_requests
- dev
- main
# Build stage
build:
stage: build
script:
- npm install
- npm run build
- cd infrastructure && npm run build
artifacts:
paths:
- infrastructure/cdk.out/
- services/*/dist/
expire_in: 1 hour
only:
- dev
- main
# Deploy to dev
deploy:dev:
stage: deploy
script:
- npm install -g aws-cdk
- cd infrastructure
- npx cdk deploy --all --require-approval never --context environment=dev
environment:
name: development
url: https://api.everyonecook.cloud
only:
- dev
when: manual
# Deploy to production
deploy:prod:
stage: deploy
script:
- npm install -g aws-cdk
- cd infrastructure
- npx cdk deploy --all --require-approval never --context environment=prod
environment:
name: production
url: https://api.everyonecook.cloud
only:
- main
when: manual
EOF
2. Commit CI/CD Configuration
# Add and commit
git add .gitlab-ci.yml
git commit -m "Add GitLab CI/CD configuration"
git push
Screenshot: GitLab showing CI/CD pipeline
1. Add AWS Credentials
AWS_ACCESS_KEY_ID: Your AWS access keyAWS_SECRET_ACCESS_KEY: Your AWS secret key (masked)AWS_DEFAULT_REGION: us-east-1
Screenshot: GitLab CI/CD variables configuration
2. Add Environment Variables
Add other environment variables:
DOMAIN_NAME: everyonecook.cloudENABLE_OPENSEARCH: false1. Protect Main Branch
main branch2. Protect Dev Branch
dev branch1. Create Feature Branch
# Create feature branch
git checkout dev
git pull
git checkout -b feature/new-feature
# Make changes
# ...
# Commit changes
git add .
git commit -m "Add new feature"
git push -u origin feature/new-feature
2. Create Merge Request
3. Review and Merge
1. Create Release Tag
# After merging to main
git checkout main
git pull
# Create tag
git tag -a v1.0.0 -m "Release version 1.0.0"
# Push tag
git push origin v1.0.0
2. Create Release on GitLab
1. Create feature branch from dev
git checkout -b feature/new-feature
2. Make changes and commit
git add .
git commit -m "Description"
3. Push to GitLab
git push -u origin feature/new-feature
4. Create merge request on GitLab
feature/new-feature → dev
5. Review, test, and merge
6. Deploy to dev environment
(manual trigger in GitLab CI/CD)
7. Test in dev environment
8. Merge dev → main for production
9. Deploy to production
(manual trigger in GitLab CI/CD)
10. Tag release
git tag -a v1.0.0 -m "Release"
Commit Messages:
feat: Add user authentication
fix: Fix login bug
docs: Update README
style: Format code
refactor: Refactor user service
test: Add unit tests
chore: Update dependencies
Branch Naming:
feature/add-notifications
bugfix/fix-login-error
hotfix/critical-security-patch
release/v1.0.0
Issue: Authentication failed
# Use personal access token instead of password
# Generate token: GitLab → Settings → Access Tokens
# Use token as password when pushing
Issue: Large files rejected
# Check file size
git ls-files -z | xargs -0 du -h | sort -h
# Remove large files from history
git filter-branch --tree-filter 'rm -f large-file.zip' HEAD
Issue: Merge conflicts
# Update your branch
git checkout feature/your-feature
git fetch origin
git merge origin/dev
# Resolve conflicts in files
# Then commit
git add .
git commit -m "Resolve merge conflicts"
git push
Once code is pushed to GitLab, proceed to Deploy to Amplify to deploy your frontend application.