Create CNAME #28
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 Deploy | |
on: [push] | |
env: | |
#variables related with the repository | |
REPOSITORY_MAIN_BRANCH: "master" | |
#variables related with the docker imager registry | |
DOCKER_IMAGE_REPOSITORY: ikcap | |
DOCKER_IMAGE_NAME: disk-website | |
#variables related with the continuous delivery | |
MANIFEST_REPOSITORY: KnowledgeCaptureAndDiscovery/k8s | |
MANIFEST_REPOSITORY_BRANCH: master | |
MANIFEST_REPOSITORY_PATH: disk-server/disk/website | |
KUSTOMIZE_IMAGE_NAME: website | |
permissions: | |
contents: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
- name: Create value as an environment variable | |
run: | | |
echo "DOCKER_TAG=${GITHUB_SHA}" >> $GITHUB_ENV | |
- name: Expose value | |
id: exposeValue | |
run: | | |
echo "::set-output name=docker_tag::${{ env.DOCKER_TAG }}" | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/[email protected] | |
if: github.event_name != 'pull_request' | |
with: | |
push: true | |
context: . | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_TAG }},${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }}:latest | |
file: ${{ env.DOCKER_FILE}} | |
outputs: | |
docker_tag: ${{ steps.exposeValue.outputs.docker_tag }} | |
update: | |
# This job the container running on k8s cluster | |
needs: [build] | |
name: "Deploy the app" | |
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out k8s manifests | |
uses: actions/checkout@v3 | |
if: github.event_name != 'pull_request' | |
with: | |
repository: ${{ env.MANIFEST_REPOSITORY }} | |
ref: ${{ env.MANIFEST_REPOSITORY_BRANCH }} | |
ssh-key: ${{ secrets.BOT_SSH }} | |
persist-credentials: true | |
- name: Setup Kustomize | |
uses: imranismail/setup-kustomize@v1 | |
if: github.event_name != 'pull_request' | |
with: | |
kustomize-version: "3.6.1" | |
- name: Update Kubernetes resources | |
if: github.event_name != 'pull_request' | |
run: | | |
cd ${{ env.MANIFEST_REPOSITORY_PATH }} | |
kustomize edit set image ${{ env.KUSTOMIZE_IMAGE_NAME }}=${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.build.outputs.docker_tag }} | |
cat kustomization.yaml | |
- name: Commit files | |
if: github.event_name != 'pull_request' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git commit -am "Disk web updated" | |
- name: Push changes | |
if: github.event_name != 'pull_request' | |
uses: ad-m/github-push-action@master | |
with: | |
ssh: true | |
branch: ${{ env.MANIFEST_REPOSITORY_BRANCH }} | |
repository: ${{ env.MANIFEST_REPOSITORY }} |