en copyright #75
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: new-page-deploy | |
on: | |
push: | |
branches: | |
- new | |
env: | |
REPO: juzi-official-website-new | |
ECR_URL: ${{ secrets.ECR_URL }} | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout Repositories | |
uses: actions/[email protected] | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: cn-northwest-1 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Setup NodeJS | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 16.7.0 | |
registry-url: https://npm.pkg.github.com/ | |
scope: '@juzibot' | |
- name: Create env file | |
id: create-env | |
run: | | |
touch .env | |
echo JUZI_API_TOKEN="${{ secrets.JUZI_API_TOKEN }}" >> .env | |
echo JUZI_HELLO_MSG="${{ secrets.JUZI_HELLO_MSG }}" >> .env | |
echo JUZI_API_URL="${{ secrets.JUZI_API_URL }}" >> .env | |
echo FEISHU_BOT_URL="${{ secrets.FEISHU_BOT_URL }}" >> .env | |
cat .env | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: my-ecr-repo | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
export PACKAGE_VERSION=${{ github.sha }} | |
export ECR_URL=${{ env.ECR_URL }} | |
npm run docker-ci | |
outputs: | |
version: ${{ github.sha }} | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: deploy homepage | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
script: | | |
mkdir -p ${{ secrets.DEPLOY_DIR }} | |
cd ${{ secrets.DEPLOY_DIR }} | |
sed -i -r 's/${{ env.REPO }}:[0-9a-z]{40}/${{ env.REPO }}:${{ needs.build.outputs.version }}/g' docker-compose.yml | |
AWS_CLI_MAJOR_VERSION=$(aws --version 2>&1 | cut -d " " -f1 | cut -d "/" -f2 | cut -d "." -f1) | |
if [ "$AWS_CLI_MAJOR_VERSION" = "1" ]; then | |
$(aws ecr get-login --no-include-email --region cn-northwest-1) | |
else | |
aws ecr get-login-password | docker login --username AWS --password-stdin ${{ env.ECR_URL }} 2> /dev/null >&2 | |
fi | |
docker-compose up -d | |
docker ps | |
docker system prune -af |