Docker Cloud Build #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Cloud Build | |
on: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
statuses: write | |
jobs: | |
build-and-push: | |
runs-on: ubicloud-standard-16-arm | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: | | |
image=moby/buildkit:latest | |
network=host | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Login to Amazon ECR | |
uses: aws-actions/amazon-ecr-login@v2 | |
id: login-ecr | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Get repository info | |
id: repo-info | |
run: | | |
echo "owner=$(gh repo view --json owner --jq .owner.login)" >> $GITHUB_OUTPUT | |
echo "repo=$(gh repo view --json name --jq .name)" >> $GITHUB_OUTPUT | |
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Verify branch is main | |
run: | | |
if [ "${{ steps.repo-info.outputs.branch }}" != "main" ]; then | |
echo "Not on main branch. Current branch: ${{ steps.repo-info.outputs.branch }}" | |
exit 1 | |
fi | |
- name: Verify commit signoff | |
run: | | |
SIGNOFF_COUNT=$(gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"/repos/${{ steps.repo-info.outputs.owner }}/${{ steps.repo-info.outputs.repo }}/commits/${{ steps.repo-info.outputs.sha }}/statuses" \ | |
| jq '[.[] | select(.context=="signoff" and .state=="success")] | length') | |
if [ "$SIGNOFF_COUNT" -eq 0 ]; then | |
echo "Commit has not been successfully signed off. Run 'mix signoff' first." | |
exit 1 | |
fi | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
platforms: linux/arm64 | |
build-args: | | |
MIGRATOR=Sequin.Release | |
RELEASE_NAME=sequin | |
tags: | | |
${{ secrets.ECR_URL }}/${{ secrets.IMAGE_NAME }}:${{ steps.repo-info.outputs.sha }} | |
${{ secrets.ECR_URL }}/${{ secrets.IMAGE_NAME }}:latest | |
cache-from: type=registry,ref=${{ secrets.ECR_URL }}/${{ secrets.IMAGE_NAME }}:cache | |
cache-to: type=registry,ref=${{ secrets.ECR_URL }}/${{ secrets.IMAGE_NAME }}:cache,mode=max,image-manifest=true,oci-mediatypes=true | |
provenance: false | |
- name: Report status to GitHub | |
run: | | |
gh api \ | |
--method POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"/repos/${{ steps.repo-info.outputs.owner }}/${{ steps.repo-info.outputs.repo }}/statuses/${{ steps.repo-info.outputs.sha }}" \ | |
-f context=build-and-push \ | |
-f state=success \ | |
-f description="Build and push completed successfully" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |