fix: movie batch #65
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: master(cicd) | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
ci: | |
runs-on: ubuntu-latest | |
environment: PRODUCTION | |
strategy: | |
matrix: | |
java-version: [ 11 ] | |
outputs: | |
VERSION: ${{ steps.get_version.outputs.VERSION }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Java | |
uses: actions/setup-java@v3 | |
with: | |
java-version: ${{ matrix.java-version }} | |
distribution: 'adopt' | |
- name: Cache Gradle packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
restore-keys: ${{ runner.os }}-gradle | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
- name: test | |
run: ./gradlew test | |
- name: build | |
run: ./gradlew clean build -x test | |
- name: get project version | |
id: get_version | |
run: echo "::set-output name=VERSION::${{ github.sha }}" | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build And Push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
push: true | |
tags: ${{secrets.AWS_ECR_REGISTRY_ID}}.dkr.ecr.${{secrets.AWS_REGION}}.amazonaws.com/${{secrets.AWS_ECR_REGISTRY_NAME}}:${{ steps.get_version.outputs.VERSION }} | |
cd: | |
runs-on: ubuntu-latest | |
needs: ci | |
environment: PRODUCTION | |
steps: | |
- name: checkout | |
uses: actions/checkout@master | |
- name: create remote directory | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: root | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
script: mkdir -p ~/api | |
- name: copy source via ssh key | |
uses: burnett01/[email protected] | |
with: | |
switches: -avzr | |
remote_path: ~/api | |
remote_host: ${{ secrets.HOST }} | |
remote_port: ${{ secrets.PORT }} | |
remote_user: root | |
remote_key: ${{ secrets.KEY }} | |
- name: connect ssh | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: root | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
script: | | |
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_REGISTRY_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com | |
cd ~/api | |
VERSION=${{ needs.ci.outputs.VERSION }} | |
sed -i "s/VERSION=.*/VERSION=$VERSION/" .env | |
docker-compose -f ~/api/docker-compose.yml pull | |
docker-compose -f ~/api/docker-compose.yml up --build -d | |
docker system prune --all -f |