-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (45 loc) · 1.94 KB
/
ci.yml
File metadata and controls
53 lines (45 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: agent-microservice
on: [push, pull_request, workflow_dispatch]
jobs:
buildDockerImage:
name: Build and Dockerize
runs-on: ubuntu-latest
outputs:
image_name: ${{ steps.set-tag.outputs.image_name }}
image_tag: ${{ steps.set-tag.outputs.image_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.ADMIN_GITHUB_TOKEN }}
- name: Set image name and tag
id: set-tag
run: |
echo "IMAGE_NAME=agent-microservice" >> $GITHUB_ENV
echo "image_name=agent-microservice" >> $GITHUB_OUTPUT
if [[ -n "${{ github.ref }}" && "${{ github.ref }}" =~ ^refs/tags/ ]]; then
tagNumber=$(echo "${{ github.ref }}" | sed 's#refs/tags/##')
echo "IMAGE_TAG=$tagNumber" >> $GITHUB_ENV
echo "image_tag=$tagNumber" >> $GITHUB_OUTPUT
else
calculatedSha=$(git rev-parse --short ${{ github.sha }})
tagNumber=${{ github.run_id }}-$calculatedSha
echo "IMAGE_TAG=$tagNumber" >> $GITHUB_ENV
echo "image_tag=$tagNumber" >> $GITHUB_OUTPUT
fi
- name: Confirm image name and tag
run: |
echo "Image Name: ${{ env.IMAGE_NAME }}"
echo "Image Tag: ${{ env.IMAGE_TAG }}"
- name: Build Docker image in Github container registry
run: |
lower_owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
docker build -t ghcr.io/$lower_owner/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} .
- name: Push Docker image to GHCR
run: |
lower_owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
docker push ghcr.io/$lower_owner/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}