Skip to content

Instantly share code, notes, and snippets.

@tanmay-bhat
Created December 18, 2021 11:14
Show Gist options
  • Save tanmay-bhat/9d0ff8da79c334a82b0e53038ab79d05 to your computer and use it in GitHub Desktop.
Save tanmay-bhat/9d0ff8da79c334a82b0e53038ab79d05 to your computer and use it in GitHub Desktop.
Github Action file to build Dockerfile, Push to DigitalOcean Repository and update Image tag using Kustomize
name: Go
on:
push:
branches: [ main ]
tags:
- 'v*.*.*'
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14
- name: Check out code
uses: actions/checkout@v2
- name: Extract Git Tag
run: echo "GIT_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Login to Digitalocean
uses: docker/login-action@v1
with:
registry: registry.digitalocean.com
username: ${{ secrets.DIGITAL_OCEAN_TOKEN }}
password: ${{ secrets.DIGITAL_OCEAN_TOKEN }}
- name: push image to digitalocean
run: |
docker build -t registry.digitalocean.com/tanmaybhat/saymyname:${{ env.GIT_TAG }} .
docker push registry.digitalocean.com/tanmaybhat/saymyname:${{ env.GIT_TAG }}
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: build
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Extract Git Tag
run: echo "GIT_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: update image tag in manifest
uses: imranismail/setup-kustomize@v1
- run: |
cd kustomize/base
kustomize edit set image registry.digitalocean.com/tanmaybhat/saymyname:${{ env.GIT_TAG }}
- name: Commit files
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -am "update image tag to ${{ env.GIT_TAG }}"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment