-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (74 loc) · 2.85 KB
/
Copy pathdeploy-test.yml
File metadata and controls
90 lines (74 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Build and Deploy Test to Nexlayer
on:
push:
branches-ignore:
- main
workflow_dispatch: # Allow manual triggering
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.yaml
run: |
# Extract the short SHA
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
# Update the image in nexlayer.yaml
sed -i "s|image:.*|image: ghcr.io/nexlayer/${{ env.IMAGE_NAME }}:$SHORT_SHA|" nexlayer.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.yaml
- name: Deploy to Nexlayer
run: |
# Deploy to Nexlayer using the API
curl -X POST https://app.nexlayer.io/startUserDeployment/${{ secrets.NEXLAYER_TEST_SESSION_TOKEN }} \
-H "Content-Type: text/x-yaml" \
--data-binary @nexlayer.yaml