diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..f679044 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,24 @@ +name: CD +on: + workflow_run: + workflows: ["CI"] + types: [completed] + branches: [main] + +jobs: + deploy: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + environment: production + permissions: + contents: read + steps: + - name: Deploy over SSH + uses: appleboy/ssh-action@v1.2.0 + with: + host: ${{ secrets.EC2_HOST }} + port: ${{ secrets.EC2_PORT || 22 }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_PRIVATE_KEY }} + script: | + ./deploy.sh "${{ secrets.DOCKERHUB_USERNAME }}" "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" "${{ secrets.DOCKERHUB_USERNAME }}/comeet:latest" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6eacea5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,44 @@ +name: CI +on: + pull_request: + branches: [ main ] + push: + branches: [ main ] + +jobs: + docker-build: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + - name: Extract Docker metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ secrets.DOCKERHUB_USERNAME }}/comeet + tags: | + type=raw,value=latest + type=ref,event=branch + type=sha + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: true + context: . + file: ./Dockerfile + platforms: linux/amd64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file