Skip to content

Overflow fixed

Overflow fixed #74

Workflow file for this run

name: Build and Deploy Update to Nexlayer
on:
push:
branches:
- main
env:
IMAGE_NAME: nexlayer-website
NEXLAYER_APP_NAME: nexlayer-website
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Add ARGs and ENVs to Dockerfile
run: |
# Create the ARG and ENV lines
cat << 'EOF' > /tmp/docker_vars.txt
# Build arguments
ARG ${{ secrets.ENV_VAR_NAME_1 }}
ARG ${{ secrets.ENV_VAR_NAME_2 }}
# Environment variables
ENV ${{ secrets.ENV_VAR_NAME_1 }}=$${{ secrets.ENV_VAR_NAME_1 }}
ENV ${{ secrets.ENV_VAR_NAME_2 }}=$${{ secrets.ENV_VAR_NAME_2 }}
EOF
# Insert into Dockerfile
sed -i '/^WORKDIR \/app$/r /tmp/docker_vars.txt' Dockerfile
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/nexlayer/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix=,format=short
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
${{ secrets.ENV_VAR_NAME_1 }}=${{ secrets.ENV_VAR_VALUE_1 }}
${{ secrets.ENV_VAR_NAME_2 }}=${{ secrets.ENV_VAR_VALUE_2 }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Update nexlayer-update.yaml
run: |
# Extract the short SHA
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
# Update the image in nexlayer-update.yaml
sed -i "s|image:.*|image: ghcr.io/nexlayer/${{ env.IMAGE_NAME }}:$SHORT_SHA|" nexlayer-update.yaml
# Add environment variables
sed -i '/^ path: "\/"/a\ vars:\n ${{ secrets.ENV_VAR_NAME_1 }}: ${{ secrets.ENV_VAR_VALUE_1 }}\n ${{ secrets.ENV_VAR_NAME_2 }}: ${{ secrets.ENV_VAR_VALUE_2 }}' nexlayer-update.yaml
- name: Deploy to Nexlayer
run: |
# Deploy update to Nexlayer using the API
curl -X POST https://app.nexlayer.io/startUserDeployment/${{ secrets.NEXLAYER_SESSION_TOKEN }} \
-H "Content-Type: text/x-yaml" \
--data-binary @nexlayer-update.yaml