This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
fix: update npm version #7
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 | |
env: | |
DOCKER_TAG: ${{ secrets.DOCKER_TAG }} | |
on: | |
push: {} | |
workflow_dispatch: {} | |
jobs: | |
build: | |
name: Build Docker image from the branch ${{ github.ref_name }} | |
runs-on: ubuntu-20.04 | |
environment: ${{ github.ref_name }} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v2 | |
- name: Pack Build | |
uses: dfreilich/[email protected] | |
with: | |
args: 'build tmp-cnb-image --builder heroku/buildpacks:20' | |
- name: Set default port 5000 within image | |
env: | |
SECRETS_CONTEXT: ${{ toJson(secrets) }} | |
run: | | |
echo -n "$SECRETS_CONTEXT" | jq -r '[to_entries[]|select(.key|startswith("K8S_SECRET_"))]|map("\(.key|sub("K8S_SECRET_"; ""))=\(.value|tostring|@sh)")|.[]' > secrets.env | |
cat >> Dockerfile <<EOF | |
FROM tmp-cnb-image | |
ENV PORT=5000 | |
EXPOSE 5000 | |
EOF | |
- name: login to github container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create tags based on git data | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
${{ env.DOCKER_TAG }}/${{ github.ref_name }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=raw,value=latest,enable={{is_default_branch}} | |
type=raw,value={{sha}} | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
platforms: linux/amd64 | |
push: true | |
secret-files: | | |
"secrets_env=./secrets.env" | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
deploy: | |
needs: [build] | |
name: Deploy Docker image from the branch ${{ github.ref_name }} | |
runs-on: 'ubuntu-latest' | |
environment: ${{ github.ref_name }} | |
env: | |
SECRETS_CONTEXT: ${{ toJson(secrets) }} | |
steps: | |
- uses: actions/checkout@v3 | |
name: Checkout | |
- name: Kubernetes credentials | |
run: | | |
mkdir ${HOME}/.kube | |
echo ${{ secrets.C2_KUBE_CONFIG }} | base64 --decode > ${HOME}/.kube/config | |
chmod 0600 ${HOME}/.kube/config | |
KUBE_NAMESPACE="${{ secrets.KUBE_NAMESPACE }}" | |
if [ "$KUBE_NAMESPACE"x == 'x' ] | |
then KUBE_NAMESPACE="${{ inputs.APP_NAME }}-${{ github.ref_name }}" | |
fi | |
echo "KUBE_NAMESPACE=$KUBE_NAMESPACE" >> $GITHUB_ENV | |
kubectl config set-context --current --namespace=${{ secrets.KUBE_NAMESPACE }} | |
kubectl get pod | |
- name: Create tags based on git data | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
${{ env.DOCKER_TAG }}/${{ github.ref_name }} | |
tags: | | |
type=raw,value={{sha}} | |
- name: Create auto-deploy-app-values.yaml | |
run: | | |
docker_tag="${{ steps.meta.outputs.tags }}" | |
repository=${docker_tag/:*/} | |
tag=${docker_tag/*:/} | |
cat > auto-deploy-app-values.yaml <<EOF | |
replicaCount: 1 | |
image: | |
repository: $repository | |
tag: $tag | |
pullPolicy: Always | |
extraLabels: | |
"ID": "${{ secrets.SERVICE_ID }}" | |
github: | |
app: ${{ secrets.APP_NAME }} | |
envURL: ${{ github.repositoryUrl }} | |
service: | |
enabled: true | |
name: ${{ secrets.APP_NAME }}-${{ github.ref_name }} | |
url: ${{ secrets.PUBLIC_URL }} | |
additionalHosts: | |
- ${{ secrets.APP_NAME }}-${{ github.ref_name }}.acdh-cluster.arz.oeaw.ac.at | |
type: ClusterIP | |
externalPort: 5000 | |
internalPort: 5000 | |
ingress: | |
enabled: true | |
path: "/" | |
annotations: | |
kubernetes.io/ingress.class: "nginx" | |
kubernetes.io/proxy-read-timeout: "3600" | |
EOF | |
if [ '${{ secrets.APP_ROOT }}x' != '/x' ] | |
then echo ' nginx.ingress.kubernetes.io/app-root: ${{ secrets.APP_ROOT }}' >> auto-deploy-app-values.yaml | |
fi | |
cat >> auto-deploy-app-values.yaml <<EOF | |
livenessProbe: | |
path: "${{ secrets.APP_ROOT }}" | |
initialDelaySeconds: 15 | |
timeoutSeconds: 15 | |
scheme: "HTTP" | |
probeType: "httpGet" | |
readinessProbe: | |
path: "${{ secrets.APP_ROOT }}" | |
initialDelaySeconds: 5 | |
timeoutSeconds: 3 | |
scheme: "HTTP" | |
probeType: "httpGet" | |
EOF | |
- name: Set environment variables | |
env: | |
SECRETS_CONTEXT: ${{ toJson(secrets) }} | |
run: | | |
cat > secrets.yaml <<EOF | |
apiVersion: v1 | |
kind: Secret | |
metadata: | |
name: ${{ secrets.APP_NAME }}-${{ github.ref_name }} | |
type: Opaque | |
data: | |
EOF | |
k8s_secrets=$(echo -n "$SECRETS_CONTEXT" | jq -r '[to_entries[]|select(.key|startswith("K8S_SECRET_"))]|map(" \(.key|sub("K8S_SECRET_"; "")): \(.value|tostring|@base64)")|.[]') | |
if [ "$k8s_secrets"x == 'x' ] | |
then echo ' {}' >> secrets.yaml | |
else echo "$k8s_secrets" >> secrets.yaml | |
fi | |
kubectl replace -f secrets.yaml -n "${{ secrets.KUBE_NAMESPACE }}" --force | |
rm secrets.yaml | |
- name: Deploy using helm and the local helm chart | |
env: | |
SECRETS_CONTEXT: ${{ toJson(secrets) }} | |
run: | | |
helm upgrade "${{ secrets.APP_NAME }}-${{ github.ref_name }}" \ | |
--values auto-deploy-app-values.yaml --install --atomic --wait \ | |
--set application.secretName="${{ secrets.APP_NAME }}-${{ github.ref_name }}" ${{ secrets.HELM_UPGRADE_EXTRA_ARGS }} \ | |
.github/auto-deploy-app |