From ab3cdff9afbcb162cef6ad2cc7cdf345914fe20c Mon Sep 17 00:00:00 2001 From: Andrei Balanuta <43002968+snurfer0@users.noreply.github.com> Date: Sat, 9 Dec 2023 14:41:55 +0200 Subject: [PATCH] chore: deployment action --- .github/workflows/deployer.yml | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/deployer.yml diff --git a/.github/workflows/deployer.yml b/.github/workflows/deployer.yml new file mode 100644 index 0000000..a35b51d --- /dev/null +++ b/.github/workflows/deployer.yml @@ -0,0 +1,55 @@ +name: CI/CD + +env: + IMAGE_NAME: fundraiser-dapp + +on: + push: + branches: [main] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: "Set environment variables based on the current branch" + run: | + if [[ "${{ github.ref_name }}" == "main" ]]; then + echo "ENV_FILE_BASE64=${{ secrets.ENV_FILE_BASE64_PRODUCTION }}" >> "$GITHUB_ENV" + fi + + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - name: 'Checkout repository' + uses: actions/checkout@v3 + + - name: 'Create .env file that will be used at build time' + run: | + touch .env + echo "${{ env.ENV_FILE_BASE64 }}" | base64 --decode >> .env + cat .env + + - name: 'Log in to the Container registry' + uses: docker/login-action@v2 + with: + registry: ${{ secrets.DOCKER_REGISTRY_HOST }} + username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} + + - name: "Build and push docker image" + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ secrets.DOCKER_REGISTRY_HOST }}/${{ env.IMAGE_NAME }}:latest + + - name: "Delete .env file used by Nest at build time" + run: | + rm .env \ No newline at end of file