Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 81 additions & 7 deletions .github/workflows/deploy-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,105 @@ on:
- 'main'

env:
DOCKER_USERNAME: bayu3490
IMAGE_NAME: ideagate-server-controller

jobs:
build-and-push:
test:
name: Go Test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@v2
- name: Set up Go
uses: actions/setup-go@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
go-version: 1.23

- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Install dependencies
run: go mod tidy

- name: Run unit tests
run: go test ./... -v

docker-image-build:
name: Build Docker Image
runs-on: ubuntu-latest
needs: test
outputs:
image-name-tag: ${{ steps.generate-image-name.outputs.image-name-tag }}
image-name: ${{ steps.generate-image-name.outputs.image-name }}
image-tag: ${{ steps.generate-image-name.outputs.image-tag }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- id: commit
uses: prompt/actions-commit-hash@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
- name: Generate Image Name
id: generate-image-name
run: |
echo "image-name-tag=${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.commit.outputs.short }}" >> $GITHUB_OUTPUT
echo "image-name=${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}" >> $GITHUB_OUTPUT
echo "image-tag=${{ steps.commit.outputs.short }}" >> $GITHUB_OUTPUT

- name: Build
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.commit.outputs.short }}
tags: ${{ steps.generate-image-name.outputs.image-name-tag }}

- name: Get size of the image
run: |
docker images ${{ steps.generate-image-name.outputs.image-name-tag }} --format "Image Size: {{.Size}}"

update-infrastructure:
name: Update Infrastructure
runs-on: ubuntu-latest
needs: docker-image-build

steps:
- name: Checkout Infrastructure Repo
uses: actions/checkout@v3
with:
token: '${{ secrets.GH_TOKEN }}'
fetch-depth: 0
repository: ideagate/infrastructure
ref: main
path: deployment

- name: Push Promoted Image to Infrastructure Repo
uses: kustomize-everything/action-promote@v3.7.2
id: promote
with:
target-repo: ideagate/infrastructure
target-branch: main
working-directory: deployment
images: |-
[
{
"name": "server-controller",
"newName": "${{ needs.docker-image-build.outputs.image-name }}",
"newTag": "${{ needs.docker-image-build.outputs.image-tag }}",
"overlays": ["apps/server-controller/overlays/staging"]
}
]
github-token: ${{ secrets.GH_TOKEN }}
18 changes: 15 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- '!main'

env:
DOCKER_USERNAME: bayu3490
IMAGE_NAME: ideagate-server-controller

jobs:
Expand Down Expand Up @@ -43,6 +44,10 @@ jobs:
name: Build Docker Image
runs-on: ubuntu-latest
needs: test
outputs:
image-name-tag: ${{ steps.generate-image-name.outputs.image-name-tag }}
image-name: ${{ steps.generate-image-name.outputs.image-name }}
image-tag: ${{ steps.generate-image-name.outputs.image-tag }}

steps:
- name: Checkout code
Expand All @@ -54,13 +59,20 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
- name: Generate Image Name
id: generate-image-name
run: |
echo "image-name-tag=${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.commit.outputs.short }}" >> $GITHUB_OUTPUT
echo "image-name=${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}" >> $GITHUB_OUTPUT
echo "image-tag=${{ steps.commit.outputs.short }}" >> $GITHUB_OUTPUT

- name: Build
uses: docker/build-push-action@v6
with:
context: .
push: false
tags: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.commit.outputs.short }}
tags: ${{ steps.generate-image-name.outputs.image-name-tag }}

- name: Get size of the image
run: |
docker images ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.commit.outputs.short }} --format "Image Size: {{.Size}}"
docker images ${{ steps.generate-image-name.outputs.image-name-tag }} --format "Image Size: {{.Size}}"
Loading