ci: add images to images.yml #54
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-yaml-and-deploy-to-acc: | |
name: Set images in yaml and deploy to acc | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
needs: build-and-push-docker-image | |
env: | |
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }} | |
SOPS_AGE_KEY_FILE: headless.agekey | |
SOPS_AGE_RECIPIENTS: age1pnz2leuqnfhyt9qpxjjcjs9xe9ys8xjkjn9m656wygy3ndfxya0q6kthy8 | |
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest | |
defaults: | |
run: | |
shell: bash | |
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: | | |
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 "ci: release ${{ needs.build-and-push-docker-image.outputs.image_tag }}" && \ | |
git push origin main | |
- 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 | |
# setup helm | |
- uses: azure/setup-helm@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} # only needed if version is 'latest' | |
version: 'v3.6.3' | |
id: install_helm | |
# setup kubernetes + config | |
- uses: azure/setup-kubectl@v3 | |
id: install_kubectl | |
# setup sops | |
- name: Sops Binary Installer | |
uses: mdgreenwald/mozilla-sops-action@v1.5.0 | |
id: install_sops | |
with: | |
version: "v3.7.3" | |
- name: Create age key file | |
run: | | |
echo $SOPS_AGE_KEY > $SOPS_AGE_KEY_FILE | |
# setup kubeconfig | |
- name: Setup kubeconfig | |
uses: azure/k8s-set-context@v3 | |
with: | |
method: kubeconfig | |
kubeconfig: ${{ secrets.KUBE_CONFIG}} | |
# run deployment scripts | |
- name: Run ACC deployment script | |
run: ./operations/deployments/openstad-headless/deploy-acc.sh |