|
3 | 3 | push: |
4 | 4 | branches: |
5 | 5 | - main |
6 | | -env: |
7 | | - TF_CLOUD_ORGANIZATION: "shughesuk" |
8 | | - CONFIG_DIRECTORY: "./" |
| 6 | +permissions: |
| 7 | + id-token: write # This is required for requesting tghe JWT |
| 8 | + contents: read # This is required for actions/checkout |
9 | 9 | jobs: |
10 | | - deploy-backend: |
11 | | - outputs: |
12 | | - sha: ${{ steps.short_sha.outputs.sha }} |
13 | | - environment: backend-production |
14 | | - concurrency: backend-production |
15 | | - permissions: |
16 | | - id-token: write |
17 | | - contents: read |
| 10 | + deploy-cube: |
18 | 11 | runs-on: ubuntu-latest |
19 | 12 | steps: |
20 | | - - name: Checkout code |
| 13 | + - name: Checkout repo |
21 | 14 | uses: actions/checkout@v4 |
22 | | - - name: Set up QEMU |
23 | | - uses: docker/setup-qemu-action@v3 |
24 | | - - name: Set up Docker Buildx |
25 | | - uses: docker/setup-buildx-action@v3 |
26 | | - - name: Login to Docker Hub |
27 | | - uses: docker/login-action@v3 |
| 15 | + |
| 16 | + - name: Configure AWS credentials |
| 17 | + uses: aws-actions/configure-aws-credentials@v4 |
28 | 18 | with: |
29 | | - username: ${{ secrets.DOCKERHUB_USERNAME }} |
30 | | - password: ${{ secrets.DOCKERHUB_TOKEN }} |
31 | | - - name: Get short SHA |
32 | | - id: short_sha |
33 | | - run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
34 | | - - name: Build and push Docker image |
35 | | - uses: docker/build-push-action@v5 |
| 19 | + role-to-assume: arn:aws:iam::471881062455:role/system/github_actions_role |
| 20 | + role-session-name: GitHub_to_AWS_sync_svc_cube |
| 21 | + aws-region: us-east-1 |
| 22 | + |
| 23 | + - name: Login to Amazon ECR |
| 24 | + id: login-ecr |
| 25 | + uses: aws-actions/[email protected] |
36 | 26 | with: |
37 | | - context: . |
38 | | - push: true |
39 | | - tags: shughesuk/backend:${{ steps.short_sha.outputs.sha }} |
40 | | - run-migrations: |
41 | | - name: "Run Migrations" |
42 | | - runs-on: ubuntu-latest |
43 | | - needs: deploy-backend |
44 | | - permissions: |
45 | | - contents: read |
46 | | - id-token: write |
47 | | - steps: |
48 | | - - name: Checkout |
49 | | - uses: actions/checkout@v4 |
50 | | - - name: configure aws credentials |
51 | | - uses: aws-actions/[email protected] |
| 27 | + mask-password: "false" |
| 28 | + |
| 29 | + - name: Build, tag, and push docker image to Amazon ECR |
| 30 | + env: |
| 31 | + REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 32 | + REPOSITORY: sync-svc-cube |
| 33 | + IMAGE_TAG: "${{ github.sha }}" |
| 34 | + run: | |
| 35 | + docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . |
| 36 | + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG |
| 37 | +
|
| 38 | + - name: Update cube-api Task Definition with latest image |
| 39 | + id: cube-api-task-def |
| 40 | + uses: aws-actions/[email protected] |
52 | 41 | with: |
53 | | - role-to-assume: arn:aws:iam::905418398753:role/github-actions-role |
54 | | - role-session-name: GitHub_to_AWS_via_FederatedOIDC |
55 | | - aws-region: "us-east-1" |
56 | | - - uses: prefix-dev/[email protected] |
| 42 | + task-definition-family: cube_api |
| 43 | + container-name: cube-api |
| 44 | + image: ${{ steps.login-ecr.outputs.registry }}/sync-svc-cube:${{ github.sha }} |
| 45 | + |
| 46 | + - name: Update cube-refresh-worker Task Definition with latest image |
| 47 | + id: cube-refresh-worker-task-def |
| 48 | + uses: aws-actions/[email protected] |
57 | 49 | with: |
58 | | - cache: true |
59 | | - locked: true |
60 | | - - name: Update task |
61 | | - run: pixi run python scripts/update_task.py --task-definition production --container-name backend-api --image shughesuk/backend:${{ needs.deploy-backend.outputs.sha }} |
62 | | - - name: Run migrations |
63 | | - run: pixi run python scripts/run_task.py --task-definition production --cluster production --command "pixi run python manage.py migrate" |
64 | | - terraform: |
65 | | - needs: |
66 | | - - deploy-backend |
67 | | - - run-migrations |
68 | | - name: "Terraform Apply" |
69 | | - runs-on: ubuntu-latest |
70 | | - permissions: |
71 | | - contents: read |
72 | | - steps: |
73 | | - - name: Checkout |
74 | | - uses: actions/checkout@v4 |
75 | | - - name: terraform-apply |
76 | | - |
| 50 | + task-definition-family: cube_refresh_worker |
| 51 | + container-name: cube-refresh-worker |
| 52 | + image: ${{ steps.login-ecr.outputs.registry }}/sync-svc-cube:${{ github.sha }} |
| 53 | + |
| 54 | + - name: Deploy cube-api task definition |
| 55 | + uses: aws-actions/[email protected] |
77 | 56 | with: |
78 | | - path: ./terraform |
79 | | - auto_approve: true |
80 | | - workspace: resume-workspace |
81 | | - variables: | |
82 | | - app_image = "shughesuk/backend:${{ needs.deploy-backend.outputs.sha }}" |
83 | | - env: |
84 | | - TERRAFORM_CLOUD_TOKENS: app.terraform.io=${{ secrets.TF_API_TOKEN }} |
85 | | - deploy-frontend: |
86 | | - needs: terraform |
87 | | - environment: frontend-production |
88 | | - concurrency: frontend-production |
89 | | - permissions: |
90 | | - id-token: write |
91 | | - contents: read |
92 | | - runs-on: ubuntu-latest |
93 | | - steps: |
94 | | - - name: Checkout |
95 | | - uses: actions/checkout@v4 |
96 | | - - name: configure aws credentials |
97 | | - uses: aws-actions/[email protected] |
98 | | - with: |
99 | | - role-to-assume: arn:aws:iam::905418398753:role/github-actions-role |
100 | | - role-session-name: GitHub_to_AWS_via_FederatedOIDC |
101 | | - aws-region: "us-east-1" |
102 | | - - uses: prefix-dev/[email protected] |
103 | | - env: |
104 | | - ACTIONS_STEP_DEBUG: true |
| 57 | + task-definition: ${{ steps.cube-api-task-def.outputs.task-definition }} |
| 58 | + service: cube_api |
| 59 | + cluster: production |
| 60 | + wait-for-service-stability: true |
| 61 | + |
| 62 | + - name: Deploy cube-refresh-worker task definition |
| 63 | + uses: aws-actions/[email protected] |
105 | 64 | with: |
106 | | - cache: true |
107 | | - locked: true |
108 | | - - name: Deploy |
109 | | - run: pixi run frontend-deploy |
| 65 | + task-definition: ${{ steps.cube-refresh-worker-task-def.outputs.task-definition }} |
| 66 | + service: cube_refresh_worker |
| 67 | + cluster: production |
| 68 | + wait-for-service-stability: true |
0 commit comments