Skip to content

Commit

Permalink
update workflow - deploy to docker hub
Browse files Browse the repository at this point in the history
  • Loading branch information
mpwsh committed Nov 6, 2023
1 parent 0708beb commit 7618a55
Showing 1 changed file with 68 additions and 41 deletions.
109 changes: 68 additions & 41 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,81 @@
name: Kubernetes deployment

name: Release Image
on:
push:
branches: [ dev, main ]
branches:
- main
- release

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DOCKERHUB_REPO: ${{ vars.DOCKERHUB_ORG }}/${{ github.event.repository.name }}
CACHE_CONFIG: type=s3,region=${{ vars.AWS_REGION }},bucket=${{ vars.AWS_BUCKET }},access_key_id=${{ secrets.AWS_ACCESS_KEY_ID }},secret_access_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}


jobs:
build:
name: Building and Pushing Image
runs-on: self-hosted

strategy:
matrix:
arch: [amd64, arm64]
runs-on: ${{ matrix.arch }}
environment: release
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Configure AWS credentials
-
name: Checkout
uses: actions/checkout@v3
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
run: |
docker context create ci
docker context use ci
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: image=moby/buildkit:master
version: v0.10.4
endpoint: ci
-
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ vars.AWS_REGION }}
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
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image
id: build-cm-factory-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ github.event.repository.name }}
-
name: Build and push ${{ github.event.repository.name }}
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
target: ${{ github.event.repository.name }}
push: true
provenance: false
platforms: linux/${{ matrix.arch }}
tags: ${{ vars.DOCKERHUB_ORG }}/${{ github.event.repository.name }}:latest-${{ matrix.arch }}
cache-from: ${{ env.CACHE_CONFIG }},prefix=buildx/${{ github.event.repository.name }}/${{ matrix.arch }}/
cache-to: ${{ env.CACHE_CONFIG }},prefix=buildx/${{ github.event.repository.name }}/${{ matrix.arch }}/,mode=max

run: |
git_hash=$(git rev-parse --short "$GITHUB_SHA")
git_branch=${GITHUB_REF##*/}
image_tag="$ECR_REGISTRY/$ECR_REPOSITORY:$git_branch-$git_hash"
docker build -t $image_tag .
echo "Pushing image to ECR..."
docker push $image_tag
echo "::set-output name=image::$image_tag"
finalize:
needs: build
runs-on: ubuntu-latest
environment: release
steps:
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Triggering deployment manifest update in kubes repository
uses: actions/github-script@v6
env:
BRANCH: ${{ github.ref_name }}
- name: Merge service image tags
uses: Noelware/docker-manifest-action@master
with:
github-token: ${{ secrets.ACTIONS_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'holaplex',
repo: 'kubes',
workflow_id: 'imgopt.yaml',
ref: process.env.BRANCH
})
inputs: ${{ env.DOCKERHUB_REPO }}:latest,${{ env.DOCKERHUB_REPO }}:${{ github.sha }}
images: ${{ env.DOCKERHUB_REPO }}:latest-amd64,${{ env.DOCKERHUB_REPO }}:latest-arm64
push: true

0 comments on commit 7618a55

Please sign in to comment.