diff --git a/.github/workflows/queue-service-ci.yml b/.github/workflows/queue-service-ci.yml index ac69e06..b32dd51 100644 --- a/.github/workflows/queue-service-ci.yml +++ b/.github/workflows/queue-service-ci.yml @@ -21,6 +21,7 @@ permissions: jobs: build-and-test: + name: Build and Test queue-service runs-on: ubuntu-latest steps: @@ -34,13 +35,13 @@ jobs: java-version: 17 cache: gradle - - name: Grant execute permission - run: chmod +x gradlew + - name: Grant execute permission for Gradle wrapper + run: chmod +x ./gradlew - name: Run tests env: - GPR_USER: ${{ github.actor }} - GPR_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GPR_USER: ${{ secrets.GPR_USER }} + GPR_TOKEN: ${{ secrets.GPR_TOKEN }} QUEUE_TOKEN_SECRET: ${{ secrets.QUEUE_TOKEN_SECRET }} run: ./gradlew clean test @@ -60,4 +61,4 @@ jobs: path: | build/reports/tests/test/ build/reports/problems/ - retention-days: 3 \ No newline at end of file + retention-days: 3 diff --git a/.github/workflows/queue-service-deploy.yml b/.github/workflows/queue-service-deploy.yml new file mode 100644 index 0000000..0b76c6e --- /dev/null +++ b/.github/workflows/queue-service-deploy.yml @@ -0,0 +1,72 @@ +name: Queue Service CD + +on: + push: + branches: + - main + +permissions: + contents: read + packages: write + +env: + REGISTRY: ghcr.io + IMAGE_NAME: 3s-ticketing/queue-service + IMAGE_TAG: main-latest + +jobs: + build-and-push: + name: Build and Push queue-service image + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + cache: gradle + + - name: Grant execute permission for Gradle wrapper + run: chmod +x ./gradlew + + - name: Run tests + env: + GPR_USER: ${{ secrets.GPR_USER }} + GPR_TOKEN: ${{ secrets.GPR_TOKEN }} + QUEUE_TOKEN_SECRET: ${{ secrets.QUEUE_TOKEN_SECRET }} + run: ./gradlew clean test + + - name: Log in to GitHub Container Registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Build Docker image + run: | + docker build \ + --build-arg GPR_USER=${{ secrets.GPR_USER }} \ + --build-arg GPR_TOKEN=${{ secrets.GPR_TOKEN }} \ + -t $REGISTRY/$IMAGE_NAME:$IMAGE_TAG \ + -t $REGISTRY/$IMAGE_NAME:${{ github.sha }} \ + . + + - name: Push Docker image + run: | + docker push $REGISTRY/$IMAGE_NAME:$IMAGE_TAG + docker push $REGISTRY/$IMAGE_NAME:${{ github.sha }} + + - name: Deploy queue-service to EC2 + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_SSH_KEY }} + script: | + echo "${{ secrets.GPR_TOKEN }}" | docker login ghcr.io -u ${{ secrets.GPR_USER }} --password-stdin + cd ~/deploy/ticketing/ticketing-system + docker compose -f docker-compose.app.yml pull queue-service + docker compose -f docker-compose.app.yml up -d --no-deps --force-recreate queue-service + docker ps --filter "name=ticketing-queue-service" + docker image prune -f