Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build e push de imagem OCI #8

Merged
merged 104 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from 99 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
adb42f6
Salva para testar
PedroRegisPOAR Jul 26, 2021
8f582e9
Força a action executar
PedroRegisPOAR Jul 26, 2021
fd70423
Corrige formato e adiciona logs
PedroRegisPOAR Jul 26, 2021
9d91844
Fix nomes de variáveis
PedroRegisPOAR Jul 26, 2021
debd208
Adiciona Dockefile para testar comportamento
PedroRegisPOAR Jul 26, 2021
f353d0c
Teste
PedroRegisPOAR Jul 26, 2021
d319f90
fix
PedroRegisPOAR Jul 26, 2021
e0e2ebe
Adiciona step de debug
PedroRegisPOAR Jul 26, 2021
984055d
Adiciona localhost
PedroRegisPOAR Jul 26, 2021
992034d
Troca na tag _ por -
PedroRegisPOAR Jul 26, 2021
3c6c26a
Mais ajustes
PedroRegisPOAR Jul 26, 2021
a727a1a
Remove Dockerfile
PedroRegisPOAR Jul 26, 2021
627f78a
Teste action
PedroRegisPOAR Jul 26, 2021
f0a1b74
Fix?
PedroRegisPOAR Jul 26, 2021
d3efaa0
Fix?
PedroRegisPOAR Jul 26, 2021
294d7fb
Teste
PedroRegisPOAR Jul 26, 2021
5f12d96
Teste
PedroRegisPOAR Jul 26, 2021
5e9463c
Testa o push
PedroRegisPOAR Jul 26, 2021
819c4f8
Tentativa de push
PedroRegisPOAR Jul 26, 2021
e9ed3cd
Teste 18.04
PedroRegisPOAR Jul 26, 2021
8cb3177
Teste com redhat-actions/podman-login@v1
PedroRegisPOAR Jul 26, 2021
6aa1372
Testa push para quay.io
PedroRegisPOAR Jul 26, 2021
12e2f95
Teste
PedroRegisPOAR Jul 26, 2021
2d4195b
copia configs da action do income
rodrigondec Jul 26, 2021
5e4733e
Adiciona registry: docker.pkg.github.com
PedroRegisPOAR Jul 26, 2021
42d4652
usa o repo no nome da imagem
rodrigondec Jul 26, 2021
5ad0b96
Adiciona logs com metadados do podman
PedroRegisPOAR Jul 26, 2021
d5f30e0
Fix
PedroRegisPOAR Jul 26, 2021
2c1df96
Testa action de instalação do nix com flake
PedroRegisPOAR Jul 27, 2021
55e4055
Testa build de imagem com podman do nix
PedroRegisPOAR Jul 27, 2021
54bde88
Fix make dev.build
PedroRegisPOAR Jul 27, 2021
f417369
Teste com image: localhost/imobanco/python:dev-latest
PedroRegisPOAR Jul 27, 2021
e087626
Fix?
PedroRegisPOAR Jul 27, 2021
452dd73
Mais uma tentativa
PedroRegisPOAR Jul 27, 2021
c637a97
Remove localhost do "nome" da imagem
PedroRegisPOAR Jul 27, 2021
101630e
Adiciona docker-python-image
PedroRegisPOAR Jul 27, 2021
e4ed074
Teste com IMAGE_NAME=docker-python-image/python
PedroRegisPOAR Jul 27, 2021
32454ce
Comenta env
PedroRegisPOAR Jul 27, 2021
82c58f0
Remove env
PedroRegisPOAR Jul 27, 2021
bef6849
Fixa hash
PedroRegisPOAR Jul 27, 2021
6e8e2d0
Fix
PedroRegisPOAR Jul 27, 2021
0658ff3
Fix?
PedroRegisPOAR Jul 27, 2021
add851f
Teste com nix profile install nixpkgs#podman
PedroRegisPOAR Jul 27, 2021
98aa873
Tenta dessinstalar podman via apt-get
PedroRegisPOAR Jul 27, 2021
c0664cb
Teste com sudo apt-get purge -y podman
PedroRegisPOAR Jul 27, 2021
e96358c
Teste remoção mais agressiva
PedroRegisPOAR Jul 27, 2021
2aa8f1b
Once again sudo
PedroRegisPOAR Jul 27, 2021
ca5ee23
Adiciona sudo apt-get -y uidmap
PedroRegisPOAR Jul 27, 2021
b429c2e
Usar nix para instalar as coisas deixa a gente mal acostumado
PedroRegisPOAR Jul 27, 2021
831497a
Provavelmente estava faltando os arquivos de configuração
PedroRegisPOAR Jul 27, 2021
2278651
Debug
PedroRegisPOAR Jul 27, 2021
03f3c23
Debug
PedroRegisPOAR Jul 27, 2021
b63d68d
Debug
PedroRegisPOAR Jul 27, 2021
7d29ad0
Teste
PedroRegisPOAR Jul 27, 2021
04abf00
Testa os arquivos de config
PedroRegisPOAR Jul 27, 2021
07d2899
Teste antes do PR
PedroRegisPOAR Jul 27, 2021
d35a960
Reduz debugs
PedroRegisPOAR Jul 27, 2021
db36989
Teste com --format oci
PedroRegisPOAR Jul 27, 2021
d7c3cf5
Teste com v2s2
PedroRegisPOAR Jul 27, 2021
575d867
Teste v2s1
PedroRegisPOAR Jul 27, 2021
caa4ade
Teste extra-args --format oci
PedroRegisPOAR Jul 27, 2021
d0c8c30
Teste --format docker
PedroRegisPOAR Jul 27, 2021
2c0b366
Remove extra-args: --format docker
PedroRegisPOAR Jul 27, 2021
9485916
Limpa coisas não necessárias mais
PedroRegisPOAR Jul 27, 2021
bb229ba
Adiciona alguns comentários
PedroRegisPOAR Jul 27, 2021
c19d690
Update .github/workflows/tests.yml
PedroRegisPOAR Jul 27, 2021
e82a273
Muda registry
PedroRegisPOAR Jul 27, 2021
566e718
Remove redhat-actions/buildah-build@v2 comentada
PedroRegisPOAR Jul 27, 2021
40f22d2
Teste registry ghcr.io
PedroRegisPOAR Jul 27, 2021
c572d3e
Remove --format docker
PedroRegisPOAR Jul 27, 2021
e3f5b04
Remove docker-python-image
PedroRegisPOAR Jul 27, 2021
55dc232
Remove labels não essênciais
PedroRegisPOAR Jul 27, 2021
3575943
Teste removendo imobanco/
PedroRegisPOAR Jul 27, 2021
b22e3a4
Revert "Teste removendo imobanco/"
PedroRegisPOAR Jul 27, 2021
dd7df30
Mais algumas refatorações
PedroRegisPOAR Jul 27, 2021
6323d14
sobe configurações no CI a partir do make
rodrigondec Jul 27, 2021
04afe86
algumas configurações alteradas
rodrigondec Jul 27, 2021
97c70c3
adiciona exemplo da documentação
rodrigondec Jul 27, 2021
924e1b6
troca pra aspas dupla
rodrigondec Jul 27, 2021
be39e75
adiciona shell bash
rodrigondec Jul 27, 2021
76cacaa
altera steps
rodrigondec Jul 27, 2021
09034e2
corrige steps
rodrigondec Jul 27, 2021
b28a100
pequenos ajustes
rodrigondec Jul 27, 2021
04725a3
Vários ajustes
PedroRegisPOAR Jul 28, 2021
a596aa9
Remove step antigo
PedroRegisPOAR Jul 28, 2021
19e17bd
Mais refactors
PedroRegisPOAR Jul 28, 2021
1da8bef
Fix?
PedroRegisPOAR Jul 28, 2021
b92f073
Adiciona uses: redhat-actions/push-to-registry@v2
PedroRegisPOAR Jul 28, 2021
ab147cd
Corrige make de.build -> make build
PedroRegisPOAR Jul 28, 2021
339e11a
Fix CONTAINERFILE -> CONTAINERFILE_DEV
PedroRegisPOAR Jul 28, 2021
6568dbf
Refactor
PedroRegisPOAR Jul 28, 2021
b09cf33
Debug com podman images
PedroRegisPOAR Jul 28, 2021
6d56e1f
Testa build e push
PedroRegisPOAR Jul 28, 2021
4e7d3c3
Conflito de nomes?
PedroRegisPOAR Jul 28, 2021
a28ae7d
Cria environment
PedroRegisPOAR Jul 28, 2021
2ed9334
Teste
PedroRegisPOAR Jul 28, 2021
5f7a7eb
Adiciona actions/checkout@v2
PedroRegisPOAR Jul 28, 2021
bda1f90
Mais um refactor, com duplicação de código
PedroRegisPOAR Jul 28, 2021
f3c5ee2
Adiciona podman images
PedroRegisPOAR Jul 28, 2021
68ee5b5
Update .github/workflows/tests.yml
PedroRegisPOAR Jul 28, 2021
fa50dbc
Update Makefile
PedroRegisPOAR Jul 28, 2021
e0033f8
Update .github/workflows/push.yml
PedroRegisPOAR Jul 28, 2021
41d440c
Update .github/workflows/push.yml
PedroRegisPOAR Jul 28, 2021
66fa7ba
Update .github/workflows/push.yml
PedroRegisPOAR Jul 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Faz push das imagens


on:
pull_request:
branchs:
- 'feature/**'
- 'hotfix/**'
- 'release/**'
PedroRegisPOAR marked this conversation as resolved.
Show resolved Hide resolved

jobs:
push:
name: Push
PedroRegisPOAR marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
with:
# Nix Flakes doesn't work on shallow clones
fetch-depth: 0

- uses: cachix/install-nix-action@v13
with:
install_url: https://nixos-nix-install-tests.cachix.org/serve/i6laym9jw3wg9mw6ncyrk6gjx4l34vvx/install
install_options: '--tarball-url-prefix https://nixos-nix-install-tests.cachix.org/serve'
extra_nix_config: |
experimental-features = nix-command flakes ca-references ca-derivations
sandbox = false
- run: nix flake --version
# - run: nix flake metadata nixpkgs

# Remove podman via apt-get
- run: |
sudo apt-get purge -y podman containers-image containers-common
sudo apt-get autoremove --purge
sudo apt-get -y clean
podman --version || echo podman not installed

# Instala podman usando nix
- run: nix profile install github:ES-Nix/podman-rootless/6a498059fc8a120ecc2f0d8e3712f43256c4ee1d
# Não funciona pois não vem com os arquivos de configuração
# - run: nix profile install nixpkgs#podman
- run: |
sudo apt-get update
sudo apt-get install --no-install-recommends --no-install-suggests -y uidmap
- run: podman --version
# - run: podman info --debug

- name: Faz build da imagem de dev usando podman via nix
run: |
make build
echo "::set-output name=REGISTRY::$(make print-GITHUB_REGISTRY)"
echo "::set-output name=IMAGE_NAME::$(make print-IMAGE_NAME)"
echo "::set-output name=IMAGE_TAG_DEV::$(make print-IMAGE_TAG_DEV)"
shell: bash
id: dev-build

- name: Faz build da imagem de prod usando podman via nix
run: |
make prod.build
PedroRegisPOAR marked this conversation as resolved.
Show resolved Hide resolved
echo "::set-output name=REGISTRY::$(make print-GITHUB_REGISTRY)"
echo "::set-output name=IMAGE_NAME::$(make print-IMAGE_NAME)"
echo "::set-output name=IMAGE_TAG_PROD::$(make print-IMAGE_TAG_PROD)"
shell: bash
id: prod-build

- name: Log in em Quay.io para push
uses: redhat-actions/podman-login@v1
with:
registry: ${{ steps.dev-build.outputs.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Podman Login action (https://github.com/redhat-actions/podman-login) also be used to log in,
# in which case 'username' and 'password' can be omitted.
- name: Faz push para registry da imagem de dev
id: push-to
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.dev-build.outputs.IMAGE_NAME }}
registry: ${{ steps.dev-build.outputs.REGISTRY }}
tags: ${{ steps.dev-build.outputs.IMAGE_TAG_DEV }}
- name: Print image url
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"

- name: Faz push para registry da imagem de prod
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.prod-build.outputs.IMAGE_NAME }}
registry: ${{ steps.prod-build.outputs.REGISTRY }}
tags: ${{ steps.prod-build.outputs.IMAGE_TAG_PROD }}
- name: Print image url
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"

- name: Lista imagens
run: podman images
70 changes: 56 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Test builds


on:
pull_request:
branchs:
Expand All @@ -8,19 +9,60 @@ on:
- 'release/**'

jobs:
build-dev:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Prints podman --version
run: podman --version
- name: Build dev
run: make dev.build

build-prod:
runs-on: ubuntu-18.04
build:
name: Build
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
# Nix Flakes doesn't work on shallow clones
fetch-depth: 0

- uses: cachix/install-nix-action@v13
with:
install_url: https://nixos-nix-install-tests.cachix.org/serve/i6laym9jw3wg9mw6ncyrk6gjx4l34vvx/install
install_options: '--tarball-url-prefix https://nixos-nix-install-tests.cachix.org/serve'
extra_nix_config: |
experimental-features = nix-command flakes ca-references ca-derivations
sandbox = false
- run: nix flake --version
# - run: nix flake metadata nixpkgs

# Remove podman via apt-get
- run: |
sudo apt-get purge -y podman containers-image containers-common
sudo apt-get autoremove --purge
sudo apt-get -y clean
podman --version || echo podman not installed

# Instala podman usando nix
- run: nix profile install github:ES-Nix/podman-rootless/6a498059fc8a120ecc2f0d8e3712f43256c4ee1d
# Não funciona pois não vem com os arquivos de configuração
# - run: nix profile install nixpkgs#podman
- run: |
sudo apt-get update
sudo apt-get install --no-install-recommends --no-install-suggests -y uidmap
- run: podman --version
# - run: podman info --debug

- name: Faz build da imagem de dev usando podman via nix
run: |
make build
echo "::set-output name=REGISTRY::$(make print-GITHUB_REGISTRY)"
echo "::set-output name=IMAGE_NAME::$(make print-IMAGE_NAME)"
echo "::set-output name=IMAGE_TAG_DEV::$(make print-IMAGE_TAG_DEV)"
shell: bash
id: dev-build

- name: Faz build da imagem de prod usando podman via nix
run: |
make prod.build
PedroRegisPOAR marked this conversation as resolved.
Show resolved Hide resolved
echo "::set-output name=REGISTRY::$(make print-GITHUB_REGISTRY)"
echo "::set-output name=IMAGE_NAME::$(make print-IMAGE_NAME)"
echo "::set-output name=IMAGE_TAG_PROD::$(make print-IMAGE_TAG_PROD)"
shell: bash
id: prod-build

- name: Build prod
run: make prod.build
- name: Lista imagens
run: podman images
31 changes: 31 additions & 0 deletions Containerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM python:3.8.3-slim-buster
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

está igual à de dev no momento?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quase, apenas ENV PIP_DISABLE_PIP_VERSION_CHECK 1 que está diferente, em prod está desabilitando a warn do pip que aparece toda vez que existe versão mais recente.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eu diria então pra deixar a mesma e termos uma imagem só 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eu diria então pra deixar a mesma e termos uma imagem só thinking

Não sei, não está muito claro o que vai ocorrer mais a frente, pode ser que ainda exista alguma diferença que não estamos vendo ainda.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Justo


# Set python environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIP_NO_CACHE_DIR 0
ENV PIP_DISABLE_PIP_VERSION_CHECK 1

ENV USER app_user

WORKDIR /home/app_user

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --no-install-suggests -y \
ca-certificates \
&& apt-get -y autoremove \
&& apt-get -y clean \
&& rm -rf /var/lib/apt/lists/*

RUN addgroup app_group \
&& adduser \
--quiet \
--disabled-password \
--shell /bin/bash \
--home /home/app_user \
--gecos "User" app_user \
--ingroup app_group \
&& chmod 0700 /home/app_user \
&& chown --recursive app_user:app_group /home/app_user

CMD ["/bin/bash"]
29 changes: 21 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
REGISTRY=imobanco
IMAGE_NAME=python
IMAGE_TAG=dev-latest
INCOME_API_IMAGE=$(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
GITHUB_REGISTRY=ghcr.io
IMAGE_NAME=imobanco/python
IMAGE_TAG_DEV=dev-latest
IMAGE_TAG_PROD=prod-latest
IMAGE_DEV=$(GITHUB_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG_DEV)
IMAGE_PROD=$(GITHUB_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG_PROD)
CONTAINERFILE_DEV=Containerfile.dev
CONTAINERFILE_PROD=Containerfile.prod

print-% : ; @echo $($*)

dev.build:
podman build --file Containerfile.dev --tag $(INCOME_API_IMAGE) .
build:
podman build --file $(CONTAINERFILE_DEV) --tag $(IMAGE_DEV) .

pull:
podman pull $(IMAGE_DEV)

prod.build:
PedroRegisPOAR marked this conversation as resolved.
Show resolved Hide resolved
docker build -f Dockerfile.prod .

podman build --file $(CONTAINERFILE_PROD) --tag $(IMAGE_PROD) .

login.github_registry:
podman login $(GITHUB_REGISTRY)

logout.github_registry:
podman logout $(GITHUB_REGISTRY)