# Force redeploy name: "redwoodjs-app-main" on: push: branches: - main env: # Build NODE_ENV: "development" RUNTIME_ENV: "main" # Container Registry CONTAINER_REGISTRY_HOSTNAME: ghcr.io CONTAINER_REGISTRY_USERNAME: jeliasson CONTAINER_REGISTRY_PASSWORD: ${{ secrets.__GITHUB_ACCESS_TOKEN }} CONTAINER_REGISTRY_REPOSITORY: jeliasson CONTAINER_REGISTRY_IMAGE_PREFIX: redwoodjs-app # Repository GIT_DEPLOY_REPOSITORY_NAME: jeliasson/redwoodjs-on-kubernetes-deploy GIT_DEPLOY_REPOSITORY_BRANCH: main GIT_DEPLOY_REPOSITORY_AUTHOR_NAME: jeliasson GIT_DEPLOY_REPOSITORY_AUTHOR_EMAIL: jeliasson@users.noreply.github.com GIT_DEPLOY_REPOSITORY_AUTHOR_TOKEN: ${{ secrets.__GITHUB_ACCESS_TOKEN }} jobs: # # Build # build: name: Build runs-on: ubuntu-20.04 timeout-minutes: 10 strategy: fail-fast: true matrix: platform: [api, web] include: - platform: api DATABASE_URL: __MAIN_DATABASE_URL - platform: web steps: # Checkout source code - name: Checkout source code uses: actions/checkout@v2 # Setup Docker using buildx-action - name: Setup Docker uses: docker/setup-buildx-action@v1 # Login to Docker Container Registry - name: Docker login uses: docker/login-action@v1 with: registry: ${{ env.CONTAINER_REGISTRY_HOSTNAME }} username: ${{ env.CONTAINER_REGISTRY_USERNAME }} password: ${{ env.CONTAINER_REGISTRY_PASSWORD }} # Build Docker image with a :latest and : tag - name: Docker build uses: docker/build-push-action@v2 with: push: true context: . file: ./${{ matrix.platform }}/Dockerfile build-args: | NODE_ENV=${{ env.NODE_ENV }} RUNTIME_ENV=${{ env.RUNTIME_ENV }} DATABASE_URL=${{ secrets[matrix.DATABASE_URL] }} tags: | ${{ env.CONTAINER_REGISTRY_HOSTNAME }}/${{ env.CONTAINER_REGISTRY_REPOSITORY }}/${{ env.CONTAINER_REGISTRY_IMAGE_PREFIX }}-${{ matrix.platform }}-${{ env.RUNTIME_ENV }}:latest ${{ env.CONTAINER_REGISTRY_HOSTNAME }}/${{ env.CONTAINER_REGISTRY_REPOSITORY }}/${{ env.CONTAINER_REGISTRY_IMAGE_PREFIX }}-${{ matrix.platform }}-${{ env.RUNTIME_ENV }}:${{ github.sha }} # # Configure # configure: name: Configure needs: [build] runs-on: ubuntu-20.04 timeout-minutes: 10 strategy: max-parallel: 1 fail-fast: true matrix: platform: [api, web] include: - platform: api - platform: web steps: # Checkout deployment repository - name: Checkout source code uses: actions/checkout@v2 with: submodules: recursive repository: ${{ env.GIT_DEPLOY_REPOSITORY_NAME }} ref: ${{ env.GIT_DEPLOY_REPOSITORY_BRANCH }} token: ${{ env.GIT_DEPLOY_REPOSITORY_AUTHOR_TOKEN }} # Login to Docker Container Registry - name: Docker login uses: docker/login-action@v1 with: registry: ${{ env.CONTAINER_REGISTRY_HOSTNAME }} username: ${{ env.CONTAINER_REGISTRY_USERNAME }} password: ${{ env.CONTAINER_REGISTRY_PASSWORD }} # Save these Docker credentials to the deployment repository # It will be used in Kustomize to generate a Kubernetes secret for the container registry - name: Save Container Registry credentials run: | cat $HOME/.docker/config.json | \ jq 'del(.credsStore) | del(.HttpHeaders)' > \ kubernetes/overlays/${RUNTIME_ENV}/secrets/.dockerconfigjson # Setup Kustomize - name: Setup Kustomize uses: imranismail/setup-kustomize@v1 # Use Kustomize to update the image placeholder in the Kustomize manifest file - name: Set Docker image run: | cd kubernetes/overlays/${RUNTIME_ENV} kustomize edit set image placeholder/${{ matrix.platform }}=${CONTAINER_REGISTRY_HOSTNAME}/${CONTAINER_REGISTRY_REPOSITORY}/${CONTAINER_REGISTRY_IMAGE_PREFIX}-${{ matrix.platform }}-${{ env.RUNTIME_ENV }}:${GITHUB_SHA} cat kustomization.yml # For debugging purposes, create a latest.yaml file - name: Generate Kubernetes latest manifest run: | cd kubernetes/overlays/${RUNTIME_ENV} kustomize build -o latest.yaml printf '%s\n%s\n' "# Generated with Kustomize at $(date)" "$(cat latest.yaml)" > latest.yaml # Commit our changes (e.g. the updated image tag generated by Kustomize) - name: Commit and push changes uses: EndBug/add-and-commit@v6 with: author_name: ${{ env.GIT_DEPLOY_REPOSITORY_AUTHOR_NAME }} author_email: ${{ env.GIT_DEPLOY_REPOSITORY_AUTHOR_EMAIL }} branch: ${{ env.GIT_DEPLOY_REPOSITORY_BRANCH }} message: "[ci] Deployed ${{ github.repository }}@${{ github.sha }}: ${{ github.event.head_commit.message }}" pull_strategy: "--no-ff" push: true token: ${{ env.GIT_DEPLOY_REPOSITORY_AUTHOR_TOKEN }}