-
Notifications
You must be signed in to change notification settings - Fork 8
87 lines (74 loc) · 3.8 KB
/
Copy pathstack-init.yaml
File metadata and controls
87 lines (74 loc) · 3.8 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
name: "Nextjs app Setup in AWS"
on:
workflow_dispatch:
jobs:
stack-initialization:
runs-on: ubuntu-latest
steps:
- run: echo "Creating nextjs sample application and deploying to aws s3"
- name: checkout
uses: actions/checkout@v2
with:
persist-credentials: false
- name: use node.js v14
uses: actions/setup-node@v1
with:
node-version: '14'
check-latest: true
registry-url: https://registry.npmjs.org/
- name: Stacks framework code generation
run: |
npx create-next-app nextjs-scaffold --use-npm --example "https://github.com/vercel/next-learn/tree/master/basics/learn-starter"
cp -r nextjs-scaffold/* .
rm -rf nextjs-scaffold
# npm run env -- next export -o build
# Below sed command updates the general package.json and adds next export functionality. With this npm run build command will be able to generate a out folder containing the website distribution.
sed 's/next build/next build \&\& next export/g' package.json > package1.json; mv package1.json package.json
- name: Configure git
run: |
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
git remote set-url origin https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
- name: Commit generated code and initialize workflows
run: |
git add .
git commit -m "Generate framework code and initialize workflows"
git push
# We cant push to main since its protected in this stack
### These steps ideally should be done in a deploy workflow, and referenced here
- name: npm install, build, and test
run: |
npm install
npm run build
npm run test
- name: Configure AWS credentials from your account
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Creating a bucket in s3
env:
USE_BUCKET: ${{ secrets.USE_EXISTING_BUCKET }}
if: "env.USE_BUCKET == 'false'"
run : aws s3 mb s3://${{ secrets.AWS_S3_BUCKET_NAME }}
- name: Updaing bucket policy
env:
USE_BUCKET: ${{ secrets.USE_EXISTING_BUCKET }}
if: "env.USE_BUCKET == 'false'"
run: aws s3api put-bucket-policy --bucket ${{ secrets.AWS_S3_BUCKET_NAME }} --policy '{"Statement":[{"Effect":"Allow","Principal":"*","Action":"s3:GetObject","Resource":"arn:aws:s3:::${{ secrets.AWS_S3_BUCKET_NAME }}/*"}]}'
- name: Uploading files to s3
run: aws s3 sync ./out s3://${{ secrets.AWS_S3_BUCKET_NAME }}/
- name: setting index and error files
run: aws s3 website s3://${{ secrets.AWS_S3_BUCKET_NAME }}/ --index-document index.html --error-document 404.html
- name: Get the URL to your website
env:
BUCKET: ${{ secrets.AWS_S3_BUCKET_NAME }}
REGION: ${{ secrets.AWS_REGION }}
# run: echo "Web app is installed and you can access here http://${{ env.BUCKET.s3 }}-website.${{ env.REGION }}.amazonaws.com"
run: |
git checkout
echo -e "\n\nWeb app is installed and you can access here http://${{ env.BUCKET }}.s3-website.${{ env.REGION }}.amazonaws.com" >> README.md
git add .
git commit -m "Added URL to Readme."
git push