Skip to content

ci: add images to images.yml #51

ci: add images to images.yml

ci: add images to images.yml #51

name: Build and Publish Docker Image
on:
push:
branches:
- '**'
tags:
- "v*"
jobs:
# define job to build and publish docker image
build-and-push-docker-image:
strategy:
matrix:
app: [admin-server, api-server, auth-server, image-server, cms-server]
include:
- app: api-server
build-target: release-with-packages
name: '[${{ matrix.app }}] Build & push image'
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.image_output.outputs.image_tag }}
env:
IMAGE: '${{ github.repository_owner }}/${{ matrix.app }}'
APP: ${{ matrix.app }}
BUILD_TARGET: release
steps:
- name: Checkout code
uses: actions/checkout@v3
- if: ${{ matrix.build-target }}
name: Set correct build target
run: echo "BUILD_TARGET=${{ matrix.build-target}}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
# branch event
type=ref,event=branch,suffix=-{{sha}}
# tag event
type=ref,event=tag
# - name: Set up Docker Buildx
# id: buildx
# uses: docker/setup-buildx-action@v3
#
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v3
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Build image and push to GitHub Container Registry
# id: docker_build
# uses: docker/build-push-action@v5
# with:
# context: .
# push: true
# tags: 'ghcr.io/${{ steps.meta.outputs.tags }}'
# build-args: |
# APP=${{ matrix.app }}
#
# - name: Add image output
# id: image_output
# run: echo "image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
set_images_in_acc_yaml:
name: Set images in acc yaml
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build-and-push-docker-image
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install yq
run: sudo snap install yq --channel=v4/stable
- name: Set images and commit
run: |
ls -la && \
pwd && \
git config --global user.email github@ci.push&& \
git config --global user.name GitHub && \
/snap/bin/yq -i '.admin.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/admin-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.api.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/api-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.cms.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/cms-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.auth.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/auth-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.image.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/image-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
git add operations/deployments/openstad-headless/environments/acc/images.yml && \
git commit -m "Release ${{ needs.build-and-push-docker-image.outputs.image_tag }}" && \
git push origin main
display_images_in_action:
name: Display images in Github Action
runs-on: ubuntu-latest
needs: build-and-push-docker-image
steps:
- name: Display images in Github Action
run: |
echo "**New images 🐳**
| App | Image |
|---|---|
| admin-server | \`ghcr.io/${{ github.repository_owner}}/admin-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| api-server | \`ghcr.io/${{ github.repository_owner}}/api-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| cms-server | \`ghcr.io/${{ github.repository_owner}}/cms-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| auth-server | \`ghcr.io/${{ github.repository_owner}}/auth-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| image-server | \`ghcr.io/${{ github.repository_owner}}/image-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |" >> $GITHUB_STEP_SUMMARY