@@ -221,7 +221,7 @@ jobs:
221221 run : terraform validate -no-color
222222
223223 - name : Terraform apply
224- run : terraform apply -no-color -auto-approve &> /dev/null
224+ run : terraform apply -target module.pretix -target module.pycon_backend -target module.clamav -target module.database -target module.emails -target module.cluster - no-color -auto-approve &> /dev/null
225225 env :
226226 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
227227 AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
@@ -247,11 +247,114 @@ jobs:
247247 done
248248 shell : bash
249249
250- deploy-fe :
251- runs-on : ubuntu-latest
250+ build-fe :
252251 needs : [wait-aws-update]
252+ runs-on : [self-hosted]
253+ permissions :
254+ packages : write
255+ contents : read
256+
253257 steps :
254- - name : Trigger hook
255- if : github.ref == 'refs/heads/main'
258+ - uses : actions/checkout@v4
259+ with :
260+ ref : ${{ github.ref }}
261+ fetch-depth : 0
262+ - name : Configure AWS credentials
263+ uses : aws-actions/configure-aws-credentials@v4
264+ with :
265+ aws-access-key-id : ${{ secrets.aws_access_key_id }}
266+ aws-secret-access-key : ${{ secrets.aws_secret_access_key }}
267+ aws-region : eu-central-1
268+ - name : Get service githash
269+ id : git
270+ run : |
271+ hash=$(git rev-list -1 HEAD -- frontend)
272+ echo "githash=$hash" >> $GITHUB_OUTPUT
273+ - name : Check if commit is already on ECR
274+ id : image
275+ run : |
276+ set +e
277+ aws ecr describe-images --repository-name=pythonit/pycon-frontend --image-ids=imageTag=${{ steps.git.outputs.githash }}
278+ if [[ $? == 0 ]]; then
279+ echo "image_exists=1" >> $GITHUB_OUTPUT
280+ else
281+ echo "image_exists=0" >> $GITHUB_OUTPUT
282+ fi
283+ - name : Set up QEMU dependency
284+ if : ${{ steps.image.outputs.image_exists == 0 }}
285+ uses : docker/setup-qemu-action@v3
286+ - name : Login to GitHub Packages
287+ if : ${{ steps.image.outputs.image_exists == 0 }}
288+ uses : docker/login-action@v3
289+ with :
290+ registry : ghcr.io
291+ username : ${{ github.actor }}
292+ password : ${{ secrets.GITHUB_TOKEN }}
293+ - name : Login to Amazon ECR
294+ if : ${{ steps.image.outputs.image_exists == 0 }}
295+ uses : aws-actions/amazon-ecr-login@v2
296+ - name : Set up Docker Buildx
297+ id : buildx
298+ if : ${{ steps.image.outputs.image_exists == 0 }}
299+ uses : docker/setup-buildx-action@v3
300+ - name : Get vars
301+ id : vars
302+ if : ${{ steps.image.outputs.image_exists == 0 }}
256303 run : |
257- curl -X POST ${{ secrets.VERCEL_DEPLOY_HOOK }}
304+ cms_hostname=$(aws ssm get-parameter --output text --query Parameter.Value --with-decryption --name /pythonit/${{ env.TF_WORKSPACE }}/pycon-frontend/cms-hostname)
305+ echo "CMS_HOSTNAME=$cms_hostname" >> "$GITHUB_OUTPUT"
306+
307+ conference_code=$(aws ssm get-parameter --output text --query Parameter.Value --with-decryption --name /pythonit/${{ env.TF_WORKSPACE }}/pycon-frontend/conference-code)
308+ echo "CONFERENCE_CODE=$conference_code" >> "$GITHUB_OUTPUT"
309+ - name : Build and push
310+ if : ${{ steps.image.outputs.image_exists == 0 }}
311+ uses : docker/build-push-action@v6
312+ with :
313+ context : ./frontend
314+ file : ./frontend/Dockerfile
315+ builder : ${{ steps.buildx.outputs.name }}
316+ provenance : false
317+ push : true
318+ tags : ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/pythonit/pycon-frontend:${{ steps.git.outputs.githash }}
319+ cache-from : type=local,src=/tmp/.buildx-cache
320+ cache-to : type=local,dest=/tmp/.buildx-cache
321+ platforms : linux/arm64
322+ build-args : |
323+ API_URL_SERVER=https://${{ fromJSON('["pastaporto-", ""]')[github.ref == 'refs/heads/main'] }}admin.pycon.it
324+ CMS_ADMIN_HOST=${{ fromJSON('["pastaporto-", ""]')[github.ref == 'refs/heads/main'] }}admin.pycon.it
325+ CMS_HOSTNAME=${{ steps.vars.outputs.cms_hostname }}
326+ CONFERENCE_CODE=${{ steps.vars.outputs.conference_code }}
327+
328+ deploy-fe :
329+ runs-on : ubuntu-latest
330+ needs : [build-fe]
331+ environment :
332+ name : ${{ fromJSON('["pastaporto", "production"]')[github.ref == 'refs/heads/main'] }}
333+ defaults :
334+ run :
335+ working-directory : ./infrastructure/applications
336+ steps :
337+ - uses : actions/checkout@v4
338+ with :
339+ ref : ${{ github.ref }}
340+ fetch-depth : 0
341+ - uses : hashicorp/setup-terraform@v3
342+ with :
343+ terraform_version : 1.2.4
344+ - name : Terraform Init
345+ run : terraform init
346+ env :
347+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
348+ AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
349+ AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
350+ - name : Terraform Validate
351+ id : validate
352+ run : terraform validate -no-color
353+
354+ - name : Terraform apply
355+ run : terraform apply -no-color -auto-approve &> /dev/null
356+ env :
357+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
358+ AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
359+ AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
360+ AWS_DEFAULT_REGION : eu-central-1
0 commit comments