Merge pull request #32 from snurfer0/chore/refactor #24
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: 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 at build time" | |
run: | | |
rm .env |