cicd: use right syntax to get env variables #11
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 | |
on: | |
push: | |
branches: | |
- deploy | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
- name: Generate env file | |
run: | | |
touch .env.prod | |
echo APP_HOST=${{ vars.APP_HOST }} >> .env.prod | |
echo DATABASE_HOST=${{ vars.DATABASE_HOST }} >> .env.prod | |
echo DATABASE_PORT=${{ vars.DATABASE_PORT }} >> .env.prod | |
echo TOKEN_SECRET="${{ secrets.TOKEN_SECRET }}" >> .env.prod | |
echo CRYPTO_KEY="${{ secrets.CRYPTO_KEY }}" >> .env.prod | |
cat .env.prod | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22.x' | |
- name: Install frontend dependencies | |
run: npm ci | |
- name: Build frontend | |
run: npm run prod | |
- name: Login to DockerHub | |
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build docker | |
run: docker build . -t dorianneto/burn-secret-web -f ./.docker/go/Dockerfile --platform linux/amd64 | |
- name: Push docker | |
run: docker push dorianneto/burn-secret-web:latest | |
deploy: | |
runs-on: self-hosted | |
needs: build | |
steps: | |
- name: Pull docker image | |
run: docker pull dorianneto/burn-secret-web:latest | |
- name: Remove current container | |
run: docker rm -f burn-secret-web-container | |
- name: Remove old images | |
run: docker rmi $(docker images --filter "dangling=true" -q --no-trunc) | |
- name: Runs container | |
run: docker run -d -p 80:80 -e APP_ENV=prod --name burn-secret-web-container dorianneto/burn-secret-web |