Skip to content

Commit

Permalink
Clean up workflows, keep the build test pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Guysnacho committed Oct 23, 2024
1 parent 6c22e9c commit 2dad904
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 86 deletions.
41 changes: 5 additions & 36 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on:
push:
branches:
- "33-Scaffold-and-use-ECR"
- " "
permissions:
pull-requests: write
name: ✨ Build Test 🧐
Expand Down Expand Up @@ -33,9 +33,9 @@ jobs:
run: |
cd terraform
terraform apply -var="bucket-name=${{ secrets.S3_BUCKET }}" -var="db-name=${{ secrets.DB_NAME }}" -var="db-username=${{ secrets.DB_USER }}" -auto-approve
- run: echo ${{ steps.plan.outputs.stdout }}
- run: echo ${{ steps.plan.outputs.stderr }}
- run: echo ${{ steps.plan.outputs.exitcode }}
# - run: echo ${{ steps.plan.outputs.stdout }}
# - run: echo ${{ steps.plan.outputs.stderr }}
# - run: echo ${{ steps.plan.outputs.exitcode }}
- name: Fetch API GW
id: APIGW
run: |
Expand Down Expand Up @@ -94,40 +94,9 @@ jobs:
ECR_REPOSITORY: ecr-ex-config
IMAGE_TAG: latest
run: |
# Build a docker container and push it to ECR
echo "Building a docker image"
cd web
docker build -t ${{env.ECR_REGISTRY}}/${{env.ECR_REPOSITORY}}:${{env.IMAGE_TAG}} .
echo "Pushing image to ECR..."
docker push ${{env.ECR_REGISTRY}}/${{env.ECR_REPOSITORY}}:${{env.IMAGE_TAG}}
echo "artifact-url=${{env.ECR_REGISTRY}}/${{env.ECR_REPOSITORY}}:${{env.IMAGE_TAG}}" >> $GITHUB_OUTPUT
# - name: 🐳 Build Image
# uses: docker/build-push-action@v6
# with:
# context: ./web/
# file: ./web/Dockerfile
# push: true # if we wanted to push the image to DockerHub or a local registry
# tags: ecr-ex-config
# # cache-to: type=local,dest=user/app:cache
# outputs: type=local,dest=./alpine_storefront,type=image,dest=${{needs.TF-Apply.outputs.registry_url}}/ecr-ex-config:latest
# secret-envs: NEXT_PUBLIC_APIGW=${{needs.TF-Apply.outputs.apigw}}

# - name: Move Image to copyable location
# run: |
# stat ./alpine_storefront
# tar -zcf alpine_storefront.tar.gz ./alpine_storefront
# sudo cp ./alpine_storefront.tar.gz /home/

# - name: Upload Artifact
# uses: actions/upload-artifact@v4
# id: artifact-upload-step
# with:
# name: storefront_image
# path: /home/alpine_storefront.tar.gz
# overwrite: true
# if-no-files-found: error

# - name: Echo artifact url and send to SSM parameter
# run: |
# echo ARTIFACT_URL=${{steps.artifact-upload-step.outputs.artifact-url}}
# aws ssm put-parameter --name "ecr_artifact_url" --value "${{steps.artifact-upload-step.outputs.artifact-url}}" --type String --overwrite
50 changes: 18 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
run: |
cd terraform
terraform apply -var="bucket-name=${{ secrets.S3_BUCKET }}" -var="db-name=${{ secrets.DB_NAME }}" -var="db-username=${{ secrets.DB_USER }}" -auto-approve
- run: echo ${{ steps.plan.outputs.stdout }}
- run: echo ${{ steps.plan.outputs.stderr }}
- run: echo ${{ steps.plan.outputs.exitcode }}
# - run: echo ${{ steps.plan.outputs.stdout }}
# - run: echo ${{ steps.plan.outputs.stderr }}
# - run: echo ${{ steps.plan.outputs.exitcode }}
- name: Fetch API GW
id: APIGW
run: |
Expand Down Expand Up @@ -82,34 +82,20 @@ jobs:
aws s3 sync ./web/out s3://${{ secrets.S3_BUCKET }}/ --region us-west-2
aws s3 sync ./web/out s3://${{ secrets.S3_BUCKET }}-failover/ --region us-west-2
- name: 🐳 Build Image
uses: docker/build-push-action@v6
with:
context: ./web/
file: ./web/Dockerfile
push: true # if we wanted to push the image to DockerHub or a local registry
tags: storefront/app:latest
# cache-to: type=local,dest=user/app:cache
outputs: type=local,dest=./alpine_storefront,type=docker,dest=${{needs.TF-Apply.outputs.registry_url}}
secret-envs: NEXT_PUBLIC_APIGW=${{needs.TF-Apply.outputs.apigw}}

- name: Move Image to copyable location
run: |
stat ./alpine_storefront
ls -l
tar -zcf alpine_storefront.tar.gz ./alpine_storefront
sudo cp ./alpine_storefront.tar.gz /home/
# https://octopus.com/blog/githubactions-docker-ecr
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2.0.1

- name: Upload Artifact
uses: actions/upload-artifact@v4
id: artifact-upload-step
with:
name: storefront_image
path: /home/alpine_storefront.tar.gz
overwrite: true
if-no-files-found: error

- name: Echo artifact url and send to SSM parameter
- name: 🐳 Build and deploy image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ecr-ex-config
IMAGE_TAG: latest
run: |
echo ARTIFACT_URL=${{steps.artifact-upload-step.outputs.artifact-url}}
aws ssm put-parameter --name "ecr_artifact_url" --value "${{steps.artifact-upload-step.outputs.artifact-url}}" --type String
echo "Building a docker image"
cd web
docker build -t ${{env.ECR_REGISTRY}}/${{env.ECR_REPOSITORY}}:${{env.IMAGE_TAG}} .
echo "Pushing image to ECR..."
docker push ${{env.ECR_REGISTRY}}/${{env.ECR_REPOSITORY}}:${{env.IMAGE_TAG}}
echo "artifact-url=${{env.ECR_REGISTRY}}/${{env.ECR_REPOSITORY}}:${{env.IMAGE_TAG}}" >> $GITHUB_OUTPUT
32 changes: 14 additions & 18 deletions .github/workflows/predeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
run: |
cd terraform
terraform plan -refresh-only -var="bucket-name=${{ secrets.S3_BUCKET }}" -var="db-name=${{ secrets.DB_NAME }}" -var="db-username=${{ secrets.DB_USER }}" # -auto-approve
- run: echo ${{ steps.plan.outputs.stdout }}
- run: echo ${{ steps.plan.outputs.stderr }}
- run: echo ${{ steps.plan.outputs.exitcode }}
# - run: echo ${{ steps.plan.outputs.stdout }}
# - run: echo ${{ steps.plan.outputs.stderr }}
# - run: echo ${{ steps.plan.outputs.exitcode }}
- name: Fetch API GW
id: APIGW
run: |
Expand Down Expand Up @@ -76,20 +76,16 @@ jobs:
cd web
STATIC=1 npm run build
- name: 🐳 Build Image
uses: docker/build-push-action@v6
with:
context: ./web/
file: ./web/Dockerfile
push: false # if we wanted to push the image to DockerHub or a local registry
tags: user/app:latest
# cache-to: type=local,dest=user/app:cache
outputs: type=local,dest=./alpine_storefront
secret-envs: NEXT_PUBLIC_APIGW=${{needs.TF-Apply.outputs.apigw}}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2.0.1

- name: Move Image to copyable location
- name: 🐳 Build Image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ecr-ex-config
IMAGE_TAG: latest
run: |
stat ./alpine_storefront
ls -l
tar -zcf alpine_storefront.tar.gz ./alpine_storefront
sudo cp ./alpine_storefront.tar.gz /home/
echo "Building a docker image"
cd web
docker build -t ${{env.ECR_REGISTRY}}/${{env.ECR_REPOSITORY}}:${{env.IMAGE_TAG}} .

0 comments on commit 2dad904

Please sign in to comment.